1. The following code;
1 <Buttonx:name= "Btntest"Click= "btnTest_Click">2 <button.triggers>3 <EventTriggerRoutedEvent= "Button.Click">4 <BeginStoryboard>5 <!--the animation code to execute -6 </BeginStoryboard>7 </EventTrigger>8 </button.triggers>9 </Button>
View Code
On the button, the btntest buttons are both bound to the handle of the Click event (btnTest_Click ()), and the trigger for the routed event is added (animation is performed when clicked).
This means: When the user taps the Btntest button, the btnTest_Click () method is also triggered, and the trigger is executed, and then the animation is performed;
when you want to implement btntest in C # code , run the btnTest_Click () method directly, and the result is to execute only the contents of the method without performing the animation.
This is obviously not the result we want!!!!
It turns out that in WPF if you want to implement such a feature in C # code, you should use the RaiseEvent () method.
The specific code is as follows:
Btntest.raiseevent (New RoutedEventArgs (button.clickevent));
1 btntest.raiseevent (new RoutedEventArgs (button.clickevent));
View Code
C # code triggers mouse click events in WPF