标签:
当没有focus在listbox时,selectedItem的background为灰色,只有鼠标点击之后才会变成蓝色。希望即使鼠标没有点击的时候也是蓝色。
解决方法:
在xaml中添加:
<ListBox.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/> </ListBox.Resources>
或在app.xaml中添加:
<Style TargetType="ListBoxItem"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue"/> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/> </Style.Resources> <!--<Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="LightBlue" /> </Trigger> </Style.Triggers>--> </Style>
参考:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/38b88ef4-b4d1-4a61-a00e-e4f960896a9b/wpf-how-to-make-the-selection-item-highlight-color-stay-in-the-listbox-even-the-listbox-control?forum=wpf
https://blogs.msdn.microsoft.com/wpfsdk/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox/
WPF Tips: Specify background color of the selected item in listbox
标签:
原文地址:http://www.cnblogs.com/jane850113/p/5332309.html