WPF - change flag checkbox for image (or hide)

Can someone find out if there is an easy way to replace checkbox checkbox on image?

I have two images for the checked and unchecked states. I do not know how to use them instead of a check mark.

I also tried replacing the contents of the StackPanel and putting Image and TextBlock inside. Images are triggered by triggers. It works fine, but I have no idea how to remove the checkmark icon.

I searched a lot and found complicated solutions with tons of XAML (BulletDecorator, etc.). I personally do not like to complicate my life, and I believe that there is a simpler solution.

Checkbox to change

+4
source share
1 answer

ControlTemplate Checkbox, , . ControlTemplate Checkbox CheckBox MSDN.

ControlTemplate . , , . , , Checkbox.

WPF, ... , . , ToggleButton ControlTemplate, Checkbox, Image, , :

<ToggleButton Content="I'm An Image CheckBox Label" Foreground="Black">
    <ToggleButton.Template>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
            <StackPanel Orientation="Horizontal">
                <Image>
                    <Image.Style>
                        <Style>
                            <Setter Property="Image.Source" 
                                Value="/AppName;component/Images/Image1.jpg" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsChecked, 
                                    RelativeSource={RelativeSource AncestorType=
                                    {x:Type ToggleButton}}}" Value="True">
                                    <Setter Property="Image.Source" 
                                        Value="/AppName;component/Images/Image2.jpg" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
                <ContentPresenter Content="{TemplateBinding Content}" 
                    Margin="5,0,0,0" />
            </StackPanel>
        </ControlTemplate>
    </ToggleButton.Template>
</ToggleButton>

Checkbox, IsChecked... , , ToggleButton Checkbox, .

+14

Source: https://habr.com/ru/post/1525691/


All Articles