Click here to Skip to main content
15,881,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can made wpf mouse event?
See more: C#
Please how can I add code in wpf c# on mouse leave button?
Posted
Updated 9-Sep-11 3:25am
v2
Comments
Rhys Gravell 9-Sep-11 9:31am    
Please don't double post the same question.
Wayne Gaylard 9-Sep-11 9:43am    
Please post comments if you need to ask more questions. don't press add a solution.
Wayne Gaylard 9-Sep-11 9:47am    
To make use of the mouse functions of you control, go to the forms designer, select your button, then under properties you will see a tab called events. You scroll down to the M section and you will see all the events related to Mouse such as MouseDown, MouseLeave, MouseDoubleClick etc. You can just double click whichever event you need to handle and it will create a handler in your code behind file, where you can enter your code. Hope this helps

1 solution

OK, I am going to guess that there is more to this than handling the Mouse Leave event, but you just need to add
XML
MouseLeave="Button_MouseLeave"/>
to your XAML, and then you create the handler in the code behind like this:-

C#
private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            //Add code here
        }



I think you should explain more about what you are trying to do inside the mouse leave event so we could help more.
 
Share this answer
 
Comments
Simon Bang Terkildsen 9-Sep-11 9:38am    
That's assuming the OP knows about the xaml :) and more importantly RoutedEvents, if he doesn't he might very well see some behavior he didn't expect.
Nontheless a correct answer +5
Wayne Gaylard 9-Sep-11 9:48am    
I think he needs a very basic book on WPF. You can only help as much as you can. Thanks for the vote.
Simon Bang Terkildsen 9-Sep-11 11:31am    
true :)
Wayne Gaylard 9-Sep-11 9:42am    
OP asked:

Why use :
---------
MouseLeave="Button_MouseLeave"/>
and how can make othe mouse event such as doubleclick; R.click ,....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900