mercredi 17 février 2021

WPF Checkbox Custom Style Check disappeared

Maybe this is redundant but I could not find anything. I probably am missing something simple.

The checkbox in question is set in the codebehind on a selection event

  chkEmpOK.IsChecked = _cfgUsr.IsEnabled;

This worked as desired until I tried to add a custom style. Now the checkbox displays the text but the image/glyph/box part of the checkbox does not display. I am assuming I did something wrong in the style. Here is the control and style from the XAML:

<CheckBox x:Name="chkEmpOK" Grid.Column="2" Grid.Row="4" Margin="10,10,0,0">
    <CheckBox.Style>
        <Style TargetType="{x:Type CheckBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter Property="Content" Value="Click Me to Enable"/>
                                <Setter Property="Foreground" Value="Red"/>
                            </Trigger>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Content" Value="To remove access- click me"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </CheckBox.Style>
</CheckBox>

This is what it looks like Snippet from UI

Hopefully I am missing something simple. Does it have anything to do with it inheriting from ToggleButton?




Aucun commentaire:

Enregistrer un commentaire