调整窗口大小时内容被剪裁
我需要有关此代码的帮助:
<Grid HorizontalAlignment="Center" >
<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>
问题是,当窗口的高度大于宽度时,窗口内的网格会被剪切。有人可以帮我吗?
I need help with this code:
<Grid HorizontalAlignment="Center" >
<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>
The problem is, when the window's height is larger than it's width, the grid inside the window gets clipped. Can someone help me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将网格放入滚动查看器中会发生什么?
如果您不想使用滚动查看器,您可以将网格 MaxWidth 和 MaxHeight 绑定到 Windows 宽度和高度吗?
What happens if you put the grid in a scroll viewer?
If the case is you don't want to use a scroll viewer could you bind the Grids MaxWidth and MaxHeight to the Windows Width and Height?
为了避免在调整窗口大小时剪切内容,请使用 viewBox。感谢 HB 指出这一点!
这是我发表的原始帖子的链接:如何保持网格单元高度和宽度相同
To avoid clipping content when resizing the window, use a viewBox. Thank's to H.B. for pointing this out!
Here's the link to the original post I made : How to keep grid cell height and width the same