简体   繁体   中英

Change background color of ListBoxItem when it is not focused

I try to change the Backgroundcolor of the selected ListBoxItem when it is not focused and the containing window is not active. The Window has ShowActivated = false. But it is still grey.

Here is my code:

        <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>

I hope someone can help me, what I am doing wrong.

尝试将其添加到您的Style.Resources (根据您的喜好更改颜色):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM