Want to find the control over which mouse is placed in wpf
i have a main control in wpf. and many controls placed in main control. when mouse moves over main control i want to find over which control in main contr开发者_StackOverflow社区ol mouse is placed.
Sounds like you want UIElement.InputHitTest
. It takes in a 2D Point
(relative to the UIElement's location) and returns an IInputElement
which UIElement
implements. So for example...
Button button = myWindow.InputHitTest(mousePosition) as Button;
if (button != null)
// Blahblahblah
i would do it using a view model. bind the model's property to the mouse over event and you will automatically have this property changed when the event occurs.
精彩评论