Click here to Skip to main content
15,845,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is the issue here it is showing these error

Error XDG0018 '{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Control.Template' property on a Setter.

Error XDG0006 Object reference not set to an instance of an object.

C#
<CheckBox Content="Enable Automatic Stash Backup" Grid.Row="0" Grid.Column="1" Template="{StaticResource ResourceKey=BKCheckBox}"/>

<Style x:Key="BKCheckBox" TargetType="CheckBox">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="Foreground" Value="{StaticResource AppLightOrange}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CheckBox">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Rectangle x:Name="chkBKCheckBox" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        <TextBlock x:Name="chkBKTextBlock" Grid.Column="1" Text="{TemplateBinding}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="chkBKCheckBox" Property="Fill" Value="Green"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="chkBKCheckBox" Property="Fill" Value="White"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


What I have tried:

C#
<ControlTemplate x:Key="BKCheckBox" TargetType="CheckBox">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Rectangle x:Name="chkBKCheckBox" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        <TextBlock x:Name="chkBKTextBlock" Grid.Column="1" Text="{TemplateBinding}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="chkBKCheckBox" Property="Fill" Value="Green"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="chkBKCheckBox" Property="Fill" Value="White"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
Posted
Comments
Graeme_Grant 4-Mar-23 5:16am    
{DependencyProperty.UnsetValue}' is not a valid value

Null is not valid ... you need to work out which one ... not enough code to see what you are binding to.
Christopher Fernandes 4-Mar-23 5:35am    
This is the complete code for the checkbox what more do you need
Dave Kreskowiak 4-Mar-23 11:29am    
No, it's not. You don't show the code where this XAML is being bound to a view model, and you're not showing the view model code.

The problem seems to be coming from the view model you bound this XAML to, or some other source. A property is returning null and the XAML isn't expecting that.
Christopher Fernandes 4-Mar-23 13:10pm    
I have not yet created the ViewModel for this WPF Page on which this control is placed. This app is in the UI design phase right now.
Dave Kreskowiak 4-Mar-23 16:02pm    
You've created your own problem then. You have a property dependent on something that doesn't exist yet, like a Static Resource that doesn't exist maybe, a property that doesn't exist yet?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900