Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a pretty basic question to which I want a solution.
I have a bunch of controls on a WPF form. Some controls are within a Grid. I want these controls to stay centered within the grid when maximizing and resizing the window, but as soon as I maximize my window the controls get thrown out of position. I know this probably has someting to do with the Margin property of the controls. Can someone just please tell me how to set the margin or any other property so that the controls stay where I want them too

Thanks in advance
Posted

1 solution

Etienne_123 wrote:
Some controls are within a Grid. I want these controls to stay centered within the grid when maximizing and resizing the window


What is the parent of the grid with the controls? The parent may
be affecting the layout.

Here's an example of a grid with controls that stays centered in a window:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" ><br />        <Grid.RowDefinitions><br />            <RowDefinition Height="*" /><br />            <RowDefinition Height="*" /><br />        </Grid.RowDefinitions><br />        <Grid.ColumnDefinitions><br />            <ColumnDefinition Width="*" /><br />            <ColumnDefinition Width="*" /><br />        </Grid.ColumnDefinitions><br />        <Button Content="button1" Grid.Column="0" Grid.Row="0" /><br />        <Button Content="button2" Grid.Column="1" Grid.Row="1" /><br />    </Grid>


 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900