我可以设置ListView的非活动选择颜色
我使用了以下问题描述的解决方案
WPF ListView Inactive Selection Color
我需要更改所选非活动元素的字体颜色,有没有简单的方法来实现这一点?
谢谢
我可以设置ListView的非活动选择颜色
我使用了以下问题描述的解决方案
WPF ListView Inactive Selection Color
我需要更改所选非活动元素的字体颜色,有没有简单的方法来实现这一点?
谢谢
SystemColors.ControlTextBrushKey
,因为它只适用于项目未被选中时,或者当项目被选中但处于非活动状态时(你的问题似乎只关注后者)。然而,你可以这样做:<ListBox ...>
<ListBox.Resources>
<!-- this customizes the background color when the item is selected but inactive -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">Red</SolidColorBrush>
</ListBox.Resources>
<ListBox.ItemContainerStyle>
<Style>
<Style.Triggers>
<!-- this customizes the foreground color when the item is selected but inactive -->
<Trigger Property="Selector.IsSelected" Value="True">
<Setter Property="TextElement.Foreground" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
对于我来说,这很有效 - 在活动和非活动的ListBox中,选择的项目的前景色和背景色是相同的。
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="DodgerBlue"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="DodgerBlue"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="White"/>
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>