调整窗口内容的大小会被剪裁

时间:2011-05-07 23:02:01

标签: wpf resize window

我需要有关此代码的帮助:

<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>

问题是,当窗口的高度大于它的宽度时,窗口内的网格会被剪裁。有人能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

如果将网格放在滚动查看器中会发生什么?

如果您不想使用滚动查看器,可以将Grids MaxWidth和MaxHeight绑定到Windows宽度和高度吗?

答案 1 :(得分:0)

要避免在调整窗口大小时剪切内容,请使用viewBox。感谢H.B.指出这个! 这是我发布的原始帖子的链接:How to keep grid cell height and width the same