简体   繁体   English

为什么我的网格布局没有占据整个宽度

[英]Why my grid layout is not occupying complete width

I am having a grid which contains six rows(each row is a stack Layout). 我有一个包含六行的网格(每行是一个堆栈布局)。

Inside my fifth row(ie 5th stack layout) I am having a grid.I gave 100% width for that grid, but that grid is not occupying 100% of the width. 在我的第五行(即第五个堆栈布局)中,我有一个网格。该网格的宽度为100%,但该网格未占据宽度的100%。

How do I fix this problem? 我该如何解决这个问题?

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Vertical">
    </StackPanel>
    <StackPanel Grid.Row="1" Orientation="Vertical">
    </StackPanel>
    <StackPanel Grid.Row="2" Orientation="Vertical">
        <Grid Width="100%">
        </Grid>
    </StackPanel>
    <StackPanel Grid.Row="3" Orientation="Vertical">
    </StackPanel>
</Grid>

我认为,您可以尝试删除堆栈面板,并且可以在Grid上使用Grid.Row来解决此问题。

I haven't see percentages used in UWP before and even think it is not a valid syntax. 我以前没有看到UWP中使用的百分比,甚至认为它不是有效的语法。 I think you should use HorizontalAlignment="Stretch" instead to stretch the Grid to full width. 我认为您应该使用HorizontalAlignment="Stretch"来将Grid拉伸到完整宽度。

@Martin Zikmund and @Durai Amuthan.H's suggestions were all correct. @Martin Zikmund和@Durai Amuthan.H的建议都是正确的。 The Width=100% in UWP XAML layout doesn't support. UWP XAML布局中的Width=100%不支持。

If you want to make the Grid's has the same width as the StackPanel and automatically resize when the window resized, you could also remove the Width directly like the following: 如果要使Grid具有与StackPanel相同的宽度,并在调整窗口大小时自动调整大小,则也可以像下面这样直接删除Width

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Vertical">
    </StackPanel>
    <StackPanel Grid.Row="1" Orientation="Vertical">
    </StackPanel>
    <StackPanel Grid.Row="2" Orientation="Vertical">
        <Grid Background="Red">
            <TextBlock Text="abc"></TextBlock>
        </Grid>
    </StackPanel>
    <StackPanel Grid.Row="3" Orientation="Vertical">
    </StackPanel>
</Grid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM