一个wpf ListBox样式的问题,新手求
要设置ListBoxItem选中项的样式,但焦点不在选中项的时候样式有问题,求如何解决失去焦点时产生的样式错误,而仅与是否选中有关。
代码如下,
有如下的ListBox
<ListBox Grid.Row="1" Name="lb_CodeType" Margin="0,3,0,0" BorderThickness="0"
AlternationCount="2">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="#FFEEF2BA"></Setter>
<Setter Property="Padding" Value="3"></Setter>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightBlue"></Setter>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="SteelBlue" />
<Setter Property="Foreground" Value="Red"></Setter>
<Setter Property="BorderBrush" Value="Black"></Setter>
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="Padding" Value="2"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem Tag="1" IsSelected="True">URL</ListBoxItem>
<ListBoxItem Tag="2">HTML</ListBoxItem>
<ListBoxItem Tag="3">UNICODE</ListBoxItem>
<ListBoxItem Tag="4">BASE64</ListBoxItem>
</ListBox> wpf listbox 样式
[解决办法]
private void lb_CodeType_LostFocus(object sender, RoutedEventArgs e)
{
lb_CodeType.SelectedIndex = -1;
}