首页 > Windows开发 > 详细

WPF Tips: Specify background color of the selected item in listbox

时间:2016-03-29 12:33:48      阅读:347      评论:0      收藏:0      [点我收藏+]

当没有focus在listbox时,selectedItem的background为灰色,只有鼠标点击之后才会变成蓝色。希望即使鼠标没有点击的时候也是蓝色。

解决方法:

在xaml中添加:

<ListBox.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/> </ListBox.Resources>

或在app.xaml中添加:

<Style TargetType="ListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/>
            </Style.Resources>
            <!--<Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="LightBlue" />
                </Trigger>
            </Style.Triggers>-->
        </Style>

 

参考:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/38b88ef4-b4d1-4a61-a00e-e4f960896a9b/wpf-how-to-make-the-selection-item-highlight-color-stay-in-the-listbox-even-the-listbox-control?forum=wpf

https://blogs.msdn.microsoft.com/wpfsdk/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox/

WPF Tips: Specify background color of the selected item in listbox

原文:http://www.cnblogs.com/jane850113/p/5332309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!