How to make margin be relative to the center of the UIElement and not its top-left corner in a Grid?

Posted by Nockawa on Stack Overflow See other posts from Stack Overflow or by Nockawa
Published on 2012-04-06T22:22:32Z Indexed on 2012/04/07 11:29 UTC
Read the original article Hit count: 189

Filed under:
|
|

I'd like the Margin property to reference the center of the UIElement and not the top-left corner. That way when I change the width/height of the UIElement it stays in the same spot.

Is there a way to configure this behavior or I'll have to rely on Binding to make the adjustment ?

Thanks.

For instance if I change the Width/Height of the following rectangle, its center will move.

<Grid>
    <Rectangle Fill="#FF991C1C" Width="10" Height="40" HorizontalAlignment="Left" Margin="90,161,0,0" VerticalAlignment="Top"/>
</Grid>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about grid