我有一个应用程序在Windows 7及以下目标.net 4框架上运行愉快.
如果应用程序现在安装在Windows 8(运行.net 4.5但仍然以.net 4为目标)中,则会显示列表框或组合框中所选项目的蓝色背景以及焦点项目的白色背景.反正有没有删除它?
我在我的XAML中使用以下内容来设置有问题的样式,它似乎在Windows 8之前解决了这个问题.
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<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>
Run Code Online (Sandbox Code Playgroud) 当用户点击ListBoxItem时,我希望它是一个大胆的大字体红色背景黄色
一切都有效,除了背景.似乎所选项目有标准(蓝色)背景.如何覆盖它并将所选背景更改为黄色?
这是代码:
<Window x:Class="AlternateListBox2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:local="clr-namespace:AlternateListBox2">
<Window.Resources>
<local:Countries x:Key="countries"/>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Content" Value="{Binding Path=Name}"/>
<Setter Property="Margin" Value="2"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Background" Value="Yellow"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<ListBox
ItemsSource="{Binding Source={StaticResource countries}}"
Width="100"
Margin="10"
HorizontalAlignment="Left"
/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)