焦点在 WPF 列表框中移出时,所选项目失去样式 [英] Selected item loses style when focus moved out in WPF ListBox

查看:18
本文介绍了焦点在 WPF 列表框中移出时,所选项目失去样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么?

我有一个 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 之后,我也希望保持选中的 Item 突出显示.

I want to keep the selected Item highlighted even after focus moved out of the ListBox.

我面临什么问题?

当我选择一个项目时,IsSelected 触发器中指定的样式有效.但是,当我将焦点移出列表框(按 Tab 或单击其他控件)时,所选项目会失去其样式.有什么办法可以让我保留选中的item样式?

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?

提前致谢!

推荐答案

如果您只是设置背景颜色,请尝试将 ControlBrush 替换为 ListBox,按照 这个答案.

If you're only setting the background color, try replacing ControlBrush for the ListBox, as per this answer.

这篇关于焦点在 WPF 列表框中移出时,所选项目失去样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆