0
votes

i am new in WPF. My project have one Grid Control that grid control border is Red color and I have a one button. when i click the button grid border color will be changed to green.

How can i changed to border color using control template with DataTemplate trigger. My Goal is border color will be change using template(don't change programmatically) Screenshot will be attached.enter image description here

1

1 Answers

0
votes

You can create a property called for example IsColorChanged and bind to your DataTrigger and when button is clicked set this boolean typed property to true on the code side then DataTrigger will set to background property of your border to the green.

    <Grid>
        <Border BorderThickness="2" CornerRadius="4">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsColorChanged}" Value="True">
                            <Setter Property="Background" Value="Green"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
    </Grid>