The common question about positioning an element inside a Canvas
is "How to position the center of element (instead of the top left corner)".
- WPF: Resizing a circle, keeping the center point instead of TopLeft?
- WPF Center Ellipse at X, Y
- WPF element positioning on a Canvas
Several solutions are presented, but they all have drawbacks.
Is there a simple (XAML-only) method to position an element inside canvas so that its Canvas.Left
and Canvas.Top
correspond to the element's center AND both size and position properties can be bound to some other properties?
I've found a very easy way to do this in WPF (just set Margin="-1000000"
Positioning an element inside the Canvas by its center (instead of the top left corner) using only XAML in WPF), but it doesn't work for Silverlight/WinRT. The only other method that I know requires creating ValueConverter
to perform the x *= -0.5
calculation (which is not XAML-only).