I need to keep the Grid
cell height = width when resizing.
<Viewbox>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Background="Black" Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"></Label>
<Label Grid.Row="1" Grid.Column="0" Background="Gray" Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"></Label>
<Label Grid.Row="0" Grid.Column="1" Background="Gray" Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"></Label>
<Label Grid.Row="1" Grid.Column="1" Background="Black" Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"></Label>
</Grid>
</Viewbox>
Thank's to H.B. for the idea to use a viewBox! :)
The "proper" way to do this is probably using the shared-size features of the Grid
control, but this sadly prevents stretching the whole grid. e.g.
<Grid Grid.IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A"/>
<ColumnDefinition SharedSizeGroup="A"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="A"/>
<RowDefinition SharedSizeGroup="A"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Background="Red" Content="Lorem"/>
<Label Grid.Row="1" Grid.Column="0" Background="White" Content="Lorem ipsum"/>
<Label Grid.Row="0" Grid.Column="1" Background="White" Content="Lorem ipsum dolor"/>
<Label Grid.Row="1" Grid.Column="1" Background="Red" Content="Lorem ipsum dolor sit"/>
</Grid>
One could place this in a Viewbox
but the resize behavior of that is probably not what you want, since it zooms the contents. Maybe you can find a way to make this usable in your context.
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