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.
If your Grid has more than one row, set the RowSpan attached property to the number of rows. Then set the HorizontalAlignment property to Left or Right (which alignment you set depends on which two columns you want to resize). Finally, set the VerticalAlignment property to Stretch.
In WPF, you can create a resizable shape by using the Path control. Simply set up your shape's path data and then set the Stretch property to Fill and your shape will resize itself to fit the space available. It even takes into account the stroke thickness.
Try setting your Grid's MaxWidth to 620 (the sum of your MaxWidths) or something similar. Your Grid will stretch to fill your max size, but still be small enough for the HorizontalAlignment =Center to be observable.
Just put the grid panel inside a canvas rather than directly into the window - this will then give it X/Y co-ordinates.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With