ListBoxItem未聚焦时更改背景颜色

时间:2013-12-02 18:58:39

标签: c# wpf wpf-controls

我尝试在未聚焦时更改所选ListBoxItem的Backgroundcolor,并且包含窗口不活动。窗口有ShowActivated = false.但它仍然是灰色的。

这是我的代码:

        <ListBox x:Name="oList" >
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <EventSetter Event="MouseDoubleClick"
                             Handler="listBoxItem_DoubleClick" />
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                                     Color="LightGreen" />
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                                     Color="LightBlue" />
                </Style.Resources>
            </Style>
        </ListBox.ItemContainerStyle>

        <ListBoxItem Content="Coffie"></ListBoxItem>
        <ListBoxItem Content="Tea"></ListBoxItem>
        <ListBoxItem Content="Orange Juice"></ListBoxItem>
        <ListBoxItem Content="Milk"></ListBoxItem>
        <ListBoxItem Content="Iced Tea"></ListBoxItem>
        <ListBoxItem Content="Mango Shake"></ListBoxItem>
    </ListBox>

我希望有人可以帮助我,我做错了什么。

1 个答案:

答案 0 :(得分:1)

尝试在Style.Resources中添加此内容(根据自己的喜好更改颜色):

<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="LightBlue"/>