首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

一个wpf ListBox样式的有关问题,新手求

2013-09-28 
一个wpf ListBox样式的问题,新手求要设置ListBoxItem选中项的样式,但焦点不在选中项的时候样式有问题,求如

一个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;
        }

热点排行