Take the 2-minute tour ×

If I have a a button control and want to move it 10 pixels left repeatedly by clicking another button.

So in the second button I add the code

Rect newLayout = new Rect(Canvas.GetLeft(btnTestObject)-10, Canvas.GetTop(btnTestObject),btnTestObject.Width,btnTestObject.Height);

On clicking the button, btnTestObject moved 10 pixels to the left as desired, but that's it. On clicking the button again nothing happems. It's as if the Arrange method has moved the control visibly, but the control still thinks it is where is was originally.

So how do you move the control and update it's coordinates?

UpdateLayout is supposed to do this, but seemingly does nothing.

Any ideas?

share|improve this question

1 Answer 1

Check if this helps

Changing Position of an Element Programmatically in WPF

share|improve this answer
Yep that works. I did search S.O. first before posting, honest. Canvas.SetLeft(btnTestObject, Canvas.GetLeft(btnTestObject) - 10); –  user547708 Dec 28 '10 at 13:09

Your Answer


