zoukankan      html  css  js  c++  java
  • WPF学习笔记——设置ListBox选中项的背景颜色

    ListBox的选中项,在我这个WIN7里面,是亮蓝色,颜色是如此之浓厚,差不多遮盖了前景的字体!

    太不协调了。可是怎么设置呢?设置触发器,又是IsMouseOver,又是IsFocused,在谷歌里寻寻觅觅,无限的代码,无限的垃圾,无限的不知所谓。

    踏破铁鞋无觅处,偶然发现,应该这样写:

        <Style x:Key="UserItemContainerStyle" TargetType="ListBoxItem">
            <Style.Resources>
                <!--SelectedItem with focus-->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" Opacity=".4"/>
                <!--SelectedItem without focus-->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" Opacity=".4"/>
            </Style.Resources>
            <!-- 设置触发器 -->
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Background" Value="#efefef"/>
                    <Setter Property="Foreground" Value="Red"/>
                </Trigger>
                <Trigger Property="IsFocused" Value="true">
                    <Setter Property="Background" Value="Coral"/>
                    <Setter Property="Foreground" Value="Red"/>
                </Trigger>
            </Style.Triggers>
        </Style>

    这里设置触发器其实与选中没有关系,但还是可以用于设置鼠标滑过的样式。


  • 相关阅读:
    MySQL临时表
    git开发常用命令
    PHP资源列表
    Golang学习--平滑重启
    Golang学习--TOML配置处理
    Golang学习--包管理工具glide
    Golang学习--开篇
    构建自己的PHP框架--构建模版引擎(3)
    构建自己的PHP框架--构建模版引擎(2)
    Laravel Session 遇到的坑
  • 原文地址:https://www.cnblogs.com/leftfist/p/4257913.html
Copyright © 2011-2022 走看看