Vlad Vlad
Vlad Vlad

Reputation: 132

Wpf change control location via .X and .Y

Since I first start using WPF my problem was how to change a control location and I couldn't find anything beside .Margin = new Thickness(...), the problem is that this function isn't like the old .X and .Y.

Is there any way to change a control location on the X and Y axis in place of the old Thicnkess function ? Also I want this by code because my buttons are created dynamically.

Example: If I have a button called mybutton how do I change his location like this:

mybutton.X=...;
mybutton.Y=...;

Upvotes: 1

Views: 9216

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43636

The Canvas element is the only layout control that I can think of that uses X and Y coordinates

Example:

Button button = new Button { Content = "StackOverflow" };

Canvas canvas = new Canvas();
canvas.Children.Add(button);
Canvas.SetLeft(button, 100); //X
Canvas.SetTop(button, 10); //Y

Upvotes: 3

Related Questions