我有一个非常简单的WPF ListBox,SelectionMode设置为Multiple。
<ListBox SelectionMode="Multiple" />
当ListBox失去焦点时,很难确定已选择的内容,因为选定的颜色从蓝色变为浅灰色。最简单的改变这种行为的方法是什么,使其保持蓝色?
我知道这可能与ListItem的样式有关,但我找不到在哪里。
谢谢。
类似问题: WPF ListView Inactive Selection Color
我有一个非常简单的WPF ListBox,SelectionMode设置为Multiple。
<ListBox SelectionMode="Multiple" />
我曾经使用下面的方法在合并的ResourceDictionary中实现过类似的功能,它可能对你有所帮助:
<Style TargetType="ListBoxItem">
<Style.Resources>
<!--SelectedItem with focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" Opacity=".4"/>
<!--SelectedItem without focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey }" Color="LightBlue" Opacity=".4"/>
</Style.Resources>
</Style>
这不是对问题的回答,但当我在寻找一种禁用列表框中选择的方法时,我发现了这个。通过使用Guy和bendewey上面稍微修改过的技术,你可以在不替换底层项控件或类似的任何内容的情况下,给出列表框中没有选定项的外观。以下是我使用的代码:
<Grid.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="White" />
</Style.Resources>
</Style>
</Grid.Resources>
我也发现下面的MSDN页面很有帮助:
MSDN: SystemColors Members (System.Windows)
感谢大家的帮助。
更完整的解决方案是让新画笔引用HighlightColor:
<Style TargetType="ListBox">
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static Member=SystemColors.InactiveSelectionHighlightBrushKey}"
Color="{DynamicResource ResourceKey={x:Static Member=SystemColors.HighlightColorKey}}" />
</Style.Resources>
</Style>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue" />
</Style.Resources>
</Style>
<ListBox SelectionMode="Multiple" FocusManager.IsFocusScope="True"></ListBox>
我也遇到了这个问题。但是我通过使用IsSynchronizedWithCurrentItem="True"解决了它:
<ListBox
IsSynchronizedWithCurrentItem="True" />