繁体   English   中英

在列表视图中更改选择突出显示颜色

[英]Change selection highlight color in list view

我该怎么做呢? 我发现的所有内容都表明这应该可行,但对我而言不行。 我究竟做错了什么?

<ListView ItemsSource="{Binding ListViewItems}" >
    <ListView.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
            </Style.Resources>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

尝试直接在<ListView.Resources><SolidColorBrush x:Key=...></ListView.Resources>

还要尝试使用键"{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"定义SolidColorBrush

更新:刚刚尝试在win7上运行以下xaml并定位.net 4.5:

    <ListView ItemsSource="{Binding DummyItems}">
        <ListView.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="LightGreen"/>
        </ListView.Resources>
    </ListView>

奇迹般有效! 但是,似乎这在win8上不起作用。 因此,可能没有办法定义自己的模板。 请参阅此页面

您上面显示的代码对我有用。 但是,这将设置ListBox处于焦点时的颜色。 要在不清晰时设置颜色,请尝试...

<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Green" />

检查此示例以在Win 8上实现它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM