MouseMove works, MouseDown does not. WPF XAML

不羁的心 提交于 2019-12-12 18:21:16

问题


I made Button in Xaml. I would like to fire MouseDown event:

    MouseDown="Button_MouseDown_1"

I implemented this method in codeBehind, but it doesn't work. But if I implement this method:

    MouseMove="Button_MouseMove_1"

Implementation works. Where is the problem ?

Seba.


回答1:


The Button element itself is handling the mouse down event before your event handler gets called - meaning your event handler wont get called.

More than likely what you're actually wanting to implement is the Click event though (e.g.):

Click="button1_Click"

This will respond to the button getting clicked by the mouse or if it has focus and enter is pressed etc...

But if you really do need to specifically implement a handler for the mousedown event on the button you can use the PreviewMouseDown event which your handler will be notified of.

MSDN: Routed Events Overview can give more detail of how routed events work.



来源:https://stackoverflow.com/questions/11961084/mousemove-works-mousedown-does-not-wpf-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!