Amit
Amit

Reputation: 23

Trigger to Update Properties of a Parent Object in WPF

I am trying to change the Background Color of the ParentGrid when the child control ( Button ) ChildButton is clicked

I want to achive this using Triggers but not sure if this is even possible

Please Suggest a way to DO this through XAML only

<Grid Name="ParentGrid" Background="Red">
            <Button Name="ChildButton" />
</Grid>

Thanks

Upvotes: 0

Views: 1202

Answers (1)

Sergey Aldoukhov
Sergey Aldoukhov

Reputation: 22744

<Grid Name="ParentGrid" Background="Red">
    <Button Name="ChildButton" Margin="100">
        <Button.Triggers>
            <EventTrigger RoutedEvent="ButtonBase.Click">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation Duration="0" 
        Storyboard.TargetName="ParentGrid" 
        Storyboard.TargetProperty="Background.Color" To="Blue"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>
</Grid>

Upvotes: 1

Related Questions