Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to change button position on mouseover in wpf
Posted
Comments
Sergey Alexandrovich Kryukov 7-Feb-13 8:53am    
What did you try?
—SA

"Normal" WPF layout model is not designed to move things freely (thanks goodness!). One thing you can do it to put your button on Canvas:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[^].

This class of Panel 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 of Button:
http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx[^].

—SA
 
Share this answer
 
WPF buttons have a MouseEnter event. Add an event handler - when this event is hit, move the button. It's incredibly straightforward.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Feb-13 9:01am    
Not so apparent for the beginner. It depends what is the parent of the Button, and also related to dependency properties. For many people with System.Windows.Forms experience, this is quite mind-bending.
I explain it in my answer, please take a look.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900