【问题标题】:WPF ListBox Selection Background color changeWPF ListBox 选择背景颜色更改
【发布时间】:2016-06-15 17:05:06
【问题描述】:

我想在列表框被选中时更改它的背景颜色 我试过这个

<ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True" >
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter Property="Background" Value="Red" />
                        </Trigger>
                    </Style.Triggers>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
                    </Style.Resources>
                </Style>
            </ListBox.ItemContainerStyle>

但它没有工作。有人可以帮帮我吗?

【问题讨论】:

    标签: c# wpf listbox


    【解决方案1】:

    我认为你只是把它放在了错误的地方。试试这个。

    <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True" >
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter Property="Background" Value="Red" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
            </ListBox.Resources>
    

    【讨论】:

    • 你真的应该添加一些解释为什么这个代码应该工作 - 你也可以在代码本身中添加 cmets - 在它的当前形式中,它没有提供任何可以帮助其余部分的解释社区了解您为解决/回答问题所做的工作。
    猜你喜欢
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2012-10-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多