Change the background color based on a Boolean Binding and Setting to Different color Binding WPF

Asked

Viewed 19 times

0

I need to change the background color according to a toggle button.

I got the toogle based on:

  • TRUE: I want to apply Binding to a user-defined default color stored in the variable made Binding.
  • FALSE: I want to use a dynamic Resource with a global system color that will be changed according to the theme.

In the following code I am using the Trigger style with bindings, but it does not work. Only this working if I apply solids colors manually, if I use separate colors applying directly in background Binding works.

 <Grid Name="MainWindow" AllowDrop="False">
        <Grid.Style>
            <Style TargetType="Grid">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsUserRequiredColor}" Value="False">
                        
                        <Setter Property="Background" Value="{DynamicResource SystemThemeBackgroundColor}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsUserRequiredColor}" Value="True">
                        <Setter Property="Background" Value="{Binding DefaultUserColor}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Grid.Style>
</Grid>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.