i have a basic grid in my WPF application:
<Grid> <Grid Height="260" HorizontalAlignment="Left" Margin="24,25,0,0" Name="grid1" VerticalAlignment="Top" Width="452"> <Border BorderBrush="Red" BorderThickness="6"></Border> </Grid> </Grid> the grid is in the middle of the window. When i maximize the window i want the grid to auto resize itself to the size of the window and stay with the same margin that i specified.
How do i do that ? Do i have to calculate and resize the whole thing in the resize event?
i get from this:

to This (i dont want this):

i want the grid to resize to the same portions as it was , but for a full screen.
82 Answers
Remove Width and Height.
<Grid> <Grid Margin="24,25"> <Border BorderBrush="Red" BorderThickness="6"></Border> </Grid> </Grid> e: Added a second grid to make it identical to OP
2You could host the Grid inside of another Grid with something like:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="25" /> <RowDefinition /> <RowDefinition Height="25" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="25" /> <ColumnDefinition /> <ColumnDefinition Width="25" /> </Grid.ColumnDefinitions> <!-- Main Grid --> <Grid Grid.Row="1" Grid.Column="1"> <!-- Main Content --> </Grid> </Grid> That would allow you to put all your content inside of the Main Grid, while maintaining a constant margin of 25 around all edges.