Viewbox中的网格不会扩展到Viewbox大小

时间:2017-06-14 21:10:20

标签: c# .net wpf xaml

我希望我的整个Page具有可扩展性,因此我将Grid放入Viewbox

<Viewbox>
    <Grid>
        ...
    </Grid>
</Viewbox>

Viewbox拉伸到窗口的大小,但问题是Grid没有。 为什么会这样?

1 个答案:

答案 0 :(得分:1)

您可能希望尝试使用Viewbox的 Stretch 属性。这是我的样本:

<Viewbox Stretch="Fill">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <Button Content="Button1" Grid.Row="0"/>
            <Button Content="Button2" Grid.Row="1"/>
            <Button Content="Button3" Grid.Row="2"/>
        </Grid>
    </Viewbox>

这给出了:

enter image description here

统一给出: enter image description here

如果您想要统一填充,可能需要使用 ScrollViewer 包装Viewbox,这会提供完整的统一填充,使用滚动查看器可以滚动到您可能看不到的那些部分。如下图所示:

enter image description here

...并调整窗口大小以使所有控件都可见...

enter image description here

希望这有帮助!

相关问题