Dan*_*rik 4 .net wpf listbox listboxitem
我可以设置ListView非活动选择颜色
我使用了以下问题中描述的解决方案
我需要更改所选非活动元素的字体颜色,有没有简单的方法来实现这一点?
谢谢
遗憾的是,您无法使用,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>
Run Code Online (Sandbox Code Playgroud)
对我来说,这可行-在活动和非活动列表框中,所选项目的前景和背景颜色都相同。
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4410 次 |
| 最近记录: |