开发者

Want to find the control over which mouse is placed in wpf

开发者 https://www.devze.com 2023-01-19 05:52 出处:网络
i have a main control in wpf. and many controls placed in main control. when mouse moves over main control i want to find

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

精彩评论

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