选择时,LIstbox项目视图 [英] LIstbox items views when selected
问题描述
亲爱的,
我有一些列表框项目集合,当选择任何项目时,列表框项目边框为浅蓝色,以便清楚地看到它被选中。
I have some listbox items collection which when any items gets selected the Listbox items borders is light blue in order to clearly see that it is selected.
在这个列表中,我附上了一个右键单击可访问的上下文菜单。发生的事情是,如果我选择一个项目,然后调用上下文菜单,列表框项目将显示为未选中,因为它已失去焦点。
To this list I have attached a context menu accessible on right mouse click. What is happening is that if I select an items and then call the context menu, the listbox items appears as not selected because it has lost its focus.
如何定义我的列表框项目通过调用上下文菜单来选择它们并失去焦点时,选择的视觉效果仍然可以清晰识别?
How can I defined my listbox items in order that when they are selected and lost focus by calling the context menu, the visual selected is still clearly identifiable ?
我尝试以下位似乎不起作用:
I try the following bit does not seems to work :
<Style x:Key="HighlightContainerStyle" TargetType="ListBoxItem">
<Setter Property="Padding" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="AllowDrop" Value="True"/>
<EventSetter Event="PreviewMouseMove" Handler="ListBoxItem_PreviewMouseMoveEvent" />
<EventSetter Event="Drop" Handler="_tileGridChartView_Drop" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True" >
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="BorderBrush" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
任何想法?
regarsd
推荐答案
对不起我迟到的回复。
>>发生的事情是,如果我选择一个项目,然后调用上下文菜单,列表框项目将显示为未选中,因为它已失去焦点。
>> What is happening is that if I select an items and then call the context menu, the listbox items appears as not selected because it has lost its focus.
你如何设置焦点风格?如果我理解正确,您要禁用右键选择。
How do you set focus style ? If I understand correctly, you want to disable right-button selection.
您可以处理PreviewMouseRightButtonDown事件,然后将 " e.Handled" 设置为true以打破事件 。
You can handle PreviewMouseRightButtonDown Event then set "e.Handled" to true to break the event .
<ListBox
x:Name="lb"
ItemsSource="{Binding xx}"
PreviewMouseRightButtonDown="lb_PreviewMouseRightButtonDown"
SelectionMode="Multiple">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem...
private void lb_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
如果我有任何误解,请分享您的整个代码,以便我可以重现您的问题。
If I have any misunderstanding, please share your whole code so that I can reproduce your question.
最好的问候,
Bob
这篇关于选择时,LIstbox项目视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!