如何删除(3状态)已检查列表框项目周围不需要的红色边框?

时间:2018-05-11 11:26:53

标签: wpf xaml checkbox listboxitem

我创建了一个ListBox,每个ListBox项目都有一个三态CheckBox,每个状态都有一个自定义CheckBox图像。问题是当项目设置为第三个(null)状态时,项目周围会出现不需要的红色边框,我不知道为什么会出现这种情况或者如何将其删除。

以下是ListBox的样式:

<Style x:Key="ThreeStateCheckBoxListStyle" TargetType="{x:Type ListBox}">
    <Setter Property="SelectionMode" Value="Multiple"></Setter>
    <Setter Property="Margin" Value="8"></Setter>
    <Setter Property="Background" Value="Transparent"></Setter>
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="Margin" Value="2" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <CheckBox Focusable="False" Foreground="{StaticResource textBrush}" 
                                      IsThreeState="True" IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
                                        RelativeSource={RelativeSource TemplatedParent}}">
                                <CheckBox.Template>
                                    <ControlTemplate TargetType="{x:Type CheckBox}">
                                        <StackPanel Orientation="Horizontal">
                                            <Image x:Name="checkboxImage" Source="pack://application:,,,/Images/CheckBoxUncheck_16x.png" Width="16"
                                                   Margin="0,0,2,0" />
                                            <ContentPresenter/>
                                        </StackPanel>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="True">
                                                <Setter TargetName="checkboxImage" Property="Source" Value="pack://application:,,,/Images/CheckBox_16x.png"/>
                                            </Trigger>
                                            <Trigger Property="IsChecked" Value="{x:Null}">
                                                <Setter TargetName="checkboxImage" Property="Source" Value="pack://application:,,,/Images/CheckBoxExclude_16x.png"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </CheckBox.Template>
                                <ContentPresenter></ContentPresenter>
                            </CheckBox>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Setter.Value>
    </Setter>
</Style>

0 个答案:

没有答案