Jos*_*ant 65 wpf listview selection
我正在创建一个WPF应用程序,其中连续生成多个ListView选项(类似于iTunes浏览器).问题是默认的非活动选择颜色太浅.(见下文)

如何更改此颜色,以便我的非活动列表视图如下所示?(见下文)

使用Style类似的方法覆盖默认的SystemColor :
<Style TargetType="ListViewItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
</Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)
小智 61
改变SystemColors.ControlBrushKey不适合我,我不得不改变
SystemColors.InactiveSelectionHighlightBrushKey
所以代替:
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red" />
Run Code Online (Sandbox Code Playgroud)
我不得不使用:
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Red"/>
Run Code Online (Sandbox Code Playgroud)
Ken*_*art 57
该ListBox模板使用系统颜色称为ControlBrush设置无效高亮颜色.因此,您可以覆盖该颜色:
<ListBox>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">Red</SolidColorBrush>
</ListBox.Resources>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
Thi*_*ies 20
在某些情况下,答案将解决问题,但不是理想的,因为它在控制被禁用/只读时会中断,并且它也会覆盖颜色方案,而不是利用它们.我的建议是在ListBox标签中添加以下内容:
<ListBox....>
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="Border" Padding="2" SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
这将做什么是在选择它时(无论控制状态如何)在列表框项目上设置突出显示背景颜色.
我的回答是基于已经给出的答案的帮助,以及以下博客:http://blogs.vbcity.com/xtab/archive/2009/06/29/9344.aspx
pr0*_*g3r 10
您必须覆盖SystemColors的某些属性.看一下SystemColors Class(MSDN).InactiveSelectionHighlightBrushKey有更多属性,例如InactiveSelectionHighlightTextBrushKey,它会影响文本的颜色.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Blue"/>
<Style TargetType="ListViewItem">
<Setter Property="FontSize" Value="20" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Padding" Value="25,5" />
</Style>
</Window.Resources>
<StackPanel Orientation="Horizontal">
<ListView>
<ListViewItem Content="Item" />
<ListViewItem Content="Item" />
</ListView>
<ListView>
<ListViewItem Content="Item" />
<ListViewItem Content="Item" />
</ListView>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
38636 次 |
| 最近记录: |