当焦点移到WPF ListBox中时,所选项目会失去样式 [英] Selected item loses style when focus moved out in WPF ListBox
问题描述
我有什么?
我有一个ListBox
,其中填充了XML文件中的项目.给定Style
属性的DynamicResource
并为ItemContainerStyle
中的IsSelected
编写了触发器.
I have a ListBox
populated with items from an XML file. Given a DynamicResource
for Style
property and written trigger for IsSelected
in ItemContainerStyle
.
我想做什么?
即使焦点移出ListBox
,我仍要保持所选项目的突出显示.
I want to keep the selected Item highlighted even after focus moved out of the ListBox
.
我遇到什么问题?
当我选择一个项目时,在IsSelected
触发器中指定的样式有效.但是,当我将焦点移出列表框(按Tab或单击其他控件)时,所选项目便失去了样式.有什么办法可以保留所选的商品样式?
When I select an item the style specified in IsSelected
trigger works. But, when I move the focus out of list box (press tab or click on some other control) the selected item loses its style. Is there any way so that I can retain the selected item style?
提前谢谢!
推荐答案
If you're only setting the background color, try replacing ControlBrush
for the ListBox, as per this answer.
这篇关于当焦点移到WPF ListBox中时,所选项目会失去样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!