WPF中的鼠标悬停属性以更改位置 [英] Mouseover Property in WPF to Change Position
本文介绍了WPF中的鼠标悬停属性以更改位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在wpf中更改鼠标悬停时的按钮位置
How to change button position on mouseover in wpf
推荐答案
正常WPF布局模型不是为了自由移动而设计的(非常感谢!)。有一件事你可以把你的按钮放在Canvas
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx [ ^ ]。
此类面板
与其他类别不同,它是专为免费定位而设计的,您可以使用以下方法进行修改:
http://msdn.microsoft。 com / en-us / library / system.windows.controls.canvas.setleft.aspx [ ^ ],
http://msdn.microsoft.co m / en-us / library / system.windows.controls.canvas.settop.aspx [ ^ ]。
要实现拖动,你需要处理按钮的鼠标事件
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx [ ^ ]。
-SA
"Normal" WPF layout model is not designed to move things freely (thanks goodness!). One thing you can do it to put your button onCanvas
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[^].
This class ofPanel
is different from others, it is designed for free positioning, which you can modify using the following methods:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.setleft.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.settop.aspx[^].
To implement dragging, you will need to handle mouse events ofButton
:
http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx[^].
—SA
WPF按钮有一个 MouseEnter
事件。添加事件处理程序 - 当此事件被触发时,移动按钮。这非常简单。
WPF buttons have a MouseEnter
event. Add an event handler - when this event is hit, move the button. It''s incredibly straightforward.
这篇关于WPF中的鼠标悬停属性以更改位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文