【发布时间】:2011-08-20 19:30:22
【问题描述】:
我需要在调整大小时保持Grid 单元格高度 = 宽度。
使用 viewBox 的工作代码:
<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>
感谢 H.B.使用viewBox的想法! :)
【问题讨论】:
-
看起来你错过了代码!
-
您应该单击 Matt West 答案旁边的复选标记大纲以接受它,因为它回答了您的原始问题。另外请避免在一个问题中提出多个问题或将您的原始问题转换为完全不同的问题。如果您在裁剪搜索方面遇到问题,并且如果没有什么可以帮助就这个问题提出一个新问题。 (当然,除非修复剪辑本身被认为是一种 hack,并且您实际上想要一个更好的解决方案,这也意味着您的问题实际上没有得到充分回答)
标签: wpf grid height width cell