I wanted to get the type of the control on mouseover. Please help
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get the type of the UIElement over which the mouse is currently moving using the
MouseMoveevent. Since this is a bubbling event you can attach a handler to the container such as a Canvas.The UIElement over which the mouse is currently moving can be aquired from the the
MouseEventArgsOriginalSourceproperty.Hence to determine the type over which the mouse is moving you could use code like this:-
However you need be careful, MouseMove fires frequently as the user moves the mouse so you might want to defer any heavy work until there is some time period after the last mouse move.
There is unfortunately no bubbling mouse over event.
The other alternative is to attach the same MouseEnter handler to each child UIElement you add to the Canvas. You could use
senderinstead ofe.OriginalSourcein that case. You would have to be careful to remove the handler if the element is removed from the Canvas, else you can create what would appear to be a memory leak.