码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-03-29 12:33:57      阅读:269      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!