WPF:删除样式列表框中焦点项目周围的虚线边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/592665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF: Remove dotted border around focused item in styled listbox
提问by Vegar
I have a horizontal listbox with a custom controlIemplate. The selected item gets a dotted frame when focused. Anyone know how to get rid of it?
我有一个带有自定义控件模板的水平列表框。选中的项目在聚焦时会出现一个虚线框。有谁知道如何摆脱它?
回答by Jobi Joy
You need to set FocusVisualStyle of each ListBoxItem to null. Steps are bellow
您需要将每个 ListBoxItem 的 FocusVisualStyle 设置为 null。步骤如下
1) Create ItemContainerStyle for the ListBox
1)为ListBox创建ItemContainerStyle
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/> ....
2) Set that style to Listbox
2)将该样式设置为列表框
<ListBox ItemContainerStyle="{DynamicResource ListBoxItemStyle1}"