WPF - FocusVisualStyle 我在哪里应用它?
我有一个 UserControl
,它基本上像这样包装了 ListBox
-
<ListBox x:Name="lb" ItemsSource="{Binding ElementName=UC,Path=Pages}"
Background="{Binding ElementName=UC,Path=Background}"
BorderBrush="Transparent"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ElementName=UC,Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="20"/>
<ColumnDefinition/>
<ColumnDefinition MinWidth="20"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="1" Content="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我需要将 FocusVisualStyle
设置为 {x:Null} 隐藏此功能,但无论我在哪里应用它,我仍然得到默认的蓝色选择颜色。 我尝试在 ListBox、StackPanel 和 Grid 上设置它,但没有成功。
任何帮助都会很棒。 谢谢。
I have a UserControl
which basically wraps a ListBox
like this -
<ListBox x:Name="lb" ItemsSource="{Binding ElementName=UC,Path=Pages}"
Background="{Binding ElementName=UC,Path=Background}"
BorderBrush="Transparent"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ElementName=UC,Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="20"/>
<ColumnDefinition/>
<ColumnDefinition MinWidth="20"/>
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="1" Content="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I need to set the FocusVisualStyle
to {x:Null}
to hide this functionality but no matter where i apply it, i still get the default blue selection color. I've tried setting it on the ListBox, StackPanel and the Grid but to no avail.
Any help would be great. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FocusVisualStyle 在聚焦元素周围应用“行进的蚂蚁”,而不是背景颜色。 要更改选定 ListBoxItems 的背景颜色,请执行以下操作:
FocusVisualStyle applies the "marching ants" around the focused element, not the background color. To change the background color of selected ListBoxItems, do something like:
Kent 是正确的,当使用 Tab 键选择控件时,FocusVisualStyle 仅与键盘焦点相关。
如果您只是尝试显示没有任何选择功能的列表,您可能只需将 ListBox 降级为 ItemsControl
Kent is correct the FocusVisualStyle is only related to the Keyboard focus, when selected controls with the Tab Key.
If you are just trying to display a list without any Selection capabilities you may just be able to downgrade your ListBox to an ItemsControl