C # code triggers mouse click events in WPF

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.