dimanche 23 juillet 2017

Changing checkbox checkmark in WPF

I have a checkbox which I am trying to change the checkmark image but without success.

Here the code:

        <CheckBox Content="I'm An Image CheckBox Label" Foreground="Black">
            <CheckBox.Template>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                    <StackPanel Orientation="Horizontal">
                        <Image>
                            <Image.Style>
                                <Style>
                                    <Setter Property="Image.Source" 
            Value="./Resources/Unchecked.png" /> <--- here it fails
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsChecked, 
                RelativeSource={RelativeSource AncestorType=
                {x:Type CheckBox}}}" Value="True">
                                            <Setter Property="Image.Source" 
                    Value="./Resources/Checked.png" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                        <ContentPresenter Content="{TemplateBinding Content}" 
Margin="5,0,0,0" />
                    </StackPanel>
                </ControlTemplate>
            </CheckBox.Template>
        </CheckBox>

IsChecked is a boolean property in my view model.

At runtime is thrown an error in line where I am setting the image:

'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire