views:

30

answers:

1

I want to create a WPF control that contains elements (rectangles and ellipses) that scale and align as the container resizes. As an example, if an ellipse is set to align horizontally to the right, it always stays on the right. As the container is vertically resized, so do the child elements.

I've been looking at control tutorials for a couple hours now with some insight, but still nothing that I can get to work. Is this something that can be done entirely in XAML?

A: 

Yes, you should place your elements in Canvas panel. By setting attached properties Canvas.Left, Canvas.Right, Canvas.Top, Canvas.Bottom on your sub-elements you can align them. E.g:

<Canvas>
    <Ellipse Canvas.Left="20" Canvas.Top="20" Width="30" Height="30" Fill="Red"  />
    <Ellipse Canvas.Right="20" Canvas.Bottom="20" Width="30" Height="30" Fill="Blue"  />
</Canvas>
repka