高度为50%的UWP网格和/或StackPanel

斯蒂芬·迈耶(Stefan Meyer)

我想安排2个网格(或StackPanels)包括。Scrollviewer垂直。它们中的每一个都应为设备高度的50%。或者,更准确地说:它们在容器中,其高度应为该容器的高度的50%。据我所知,我可以将“像素”的高度设置为“自动”和“ *”,但不能设置为百分比。

应该使用什么技术来达到该目标?

到目前为止,我的代码:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Pivot Title="Pivot" >
            <PivotItem Header="Start">
                <Grid/>
            </PivotItem>
            <PivotItem Header="Baustellenbegehung">
                <Grid/>
            </PivotItem>
            <PivotItem Header="Mangelanzeige">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="0" Orientation="Vertical">
                        <ScrollViewer>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="Aktuelle Mangelanzeigen" />
                                <ListView Name="lstMangelanzeigenAktiv" />
                            </StackPanel>
                        </ScrollViewer>
                    </StackPanel>
                    <StackPanel Grid.Row="1" Orientation="Vertical">
                        <ScrollViewer>
                            <StackPanel>
                                <TextBlock Text="Archiv Mangelanzeigen" />
                                <ListView Name="lstMangelanzeigenArchiv" />
                            </StackPanel>
                        </ScrollViewer>
                    </StackPanel>
                </Grid>
            </PivotItem>
            <PivotItem Header="Zustandsfeststellungsprotokoll">
                <Grid/>
            </PivotItem>
        </Pivot>

    </Grid>

编辑:

我剥离了代码,并按建议添加了.5 *,但是当我填充ListView时,无法滚动它们:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height=".5*"/>
        <RowDefinition Height=".5*"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Vertical">
        <ScrollViewer>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="Aktuelle Mangelanzeigen" />
                <ListView Name="lstMangelanzeigenAktiv" />
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
    <StackPanel Grid.Row="1" Orientation="Vertical">
        <ScrollViewer>
            <StackPanel>
                <TextBlock Text="Archiv Mangelanzeigen" />
                <ListView Name="lstMangelanzeigenArchiv" />
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
</Grid>

编辑2:这是我当前版本的屏幕截图。我向两个ListView都添加了20个项目,并且我希望有2个滚动条(每个ListView一个):在此处输入图片说明

巴比卢姆帕(Babbillumpa)

如果您将网格用作容器,则可以按百分比设置行定义:

<Grid.RowDefinitions>
      <RowDefinition Height=".5*"/>
      <RowDefinition Height=".5*"/>
 </Grid.RowDefinitions>

这意味着这些行占据了可用高度的50%。

编辑:根据您的需要,您应该解决此问题:

       <PivotItem Header="Mangelanzeige">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0" VerticalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="TB1"/>
                        <ListView Grid.Row="1" VerticalAlignment="Stretch"/>
                    </Grid >
                    <Grid Grid.Row="1" VerticalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0"  Text="TB2"/>
                        <ListView Grid.Row="1"  VerticalAlignment="Stretch"/>
                    </Grid >
                </Grid>
            </PivotItem>

在这种情况下,使用StackPanel不允许您拉伸其内容,因此listview不能拉伸。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章