当焦点移到WPF ListBox中时,所选项目会失去样式 [英] Selected item loses style when focus moved out in WPF ListBox

查看:209
本文介绍了当焦点移到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屋!

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