vendredi 11 mai 2018

How to remove unwanted red border around (3 state) checked listbox items?

I've created a ListBox that has a three state CheckBox for each ListBox item, with a custom CheckBox images for each state. The problem is that when items are set to this third (null) state there is an unwanted red border around the item, and I don't know why this appears or how to remove it.

Here is the style for the 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>




Aucun commentaire:

Enregistrer un commentaire