【WPF】WPF ListBox的SelectedItem失去焦点的颜色

            <ListBox>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
/*这一段是关键*/ <Style.Resources>
                            <!--SelectedItem with focus-->
                            <!--<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="AliceBlue"/>-->
                            <!--SelectedItem without focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightSkyBlue" />
</Style.Resources>
                        <Setter Property="Padding" Value="8"></Setter>
                        <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
                        <Style.Triggers>
                            <Trigger  Property="IsSelected" Value="true">
                                <Setter Property="Background" Value="LightSkyBlue" />
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
                                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>

猜你喜欢

转载自www.cnblogs.com/mqxs/p/12104468.html
WPF