开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜