Storyboard trigger on click button?

When I try to run an application with this code, it throws an exception in which the error text was not found.

<Button> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:05" To="1" From="0" Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> 

There seems to be something wrong with the routed event function. What fix this exception.

+5
source share
1 answer

I think the best way is to use Behavior. It is their goal to expand the functions of the basic controls in conjunction with the possibility of reuse. You can see the fragment right here, the Windows blog (and, as I see it, it is part of the structure in the namespace: Microsoft.Xaml.Interactions.Core Assembly: Microsoft.Xaml.Interactions in Microsoft.Xaml.Interactions.dll).

 <Button x:Name="button"> <Interactivity:Interaction.Behaviors> <Core:EventTriggerBehavior EventName="Click"> <Media:ControlStoryboardAction Storyboard="storyboard1"/> </Core:EventTriggerBehavior> </Interactivity:Interaction.Behaviors> </Button> 
+4
source

Source: https://habr.com/ru/post/1247983/


All Articles