如何让GridView在XAML中包装其内容?

时间:2016-06-02 05:05:28

标签: wpf xaml gridview

作为帖子的标题,我想制作一个GridView,它可以包装里面的所有内容,这意味着如果我有3个项目,每个都有50px的高度,那么如何让GridView包含这些项目有50 * 3 = 150px的高度。 怎么做,请帮帮我!

P / s:我想通过配置XAML代码来实现,而不是在C#代码中,谢谢!

2 个答案:

答案 0 :(得分:0)

如果你没有为gridview提供高度,但是它是孩子,它自动取高度相当于孩子身高的总和。

例如,您可以执行以下操作 -

<Grid> <Grid.RowDefinitions> <RowDefinition Height="50"/> <RowDefinition Height="50"/> <RowDefinition Height="50"/> </Grid.RowDefinitions> <TextBox Grid.Row="0"/> <TextBox Grid.Row="1"/> <Button Grid.Row="2"/> </Grid>

答案 1 :(得分:0)

我找到了答案!只需将GridView的高度设置为网格行即可将其设置为自动。

                <Grid Grid.Row="0"
                      Margin="12,24">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="64" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid Opacity=".8"
                          Background="White"
                          Height="64">
                        <Grid Margin="8">
                            <TextBlock Text="Students"
                                       VerticalAlignment="Center"
                                       FontSize="24" />
                        </Grid>
                        <Grid Height="2"
                              VerticalAlignment="Bottom"
                              Background="#B0BEC5" />
                    </Grid>

                    <GridView Background="White"
                              Name="grvMatchGA"
                              Grid.Row="1"
                              ItemTemplate="{ThemeResource groupItemTemplate}"
                              Opacity=".8"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                              ScrollViewer.VerticalScrollBarVisibility="Disabled"
                              VerticalAlignment="Stretch">
                    </GridView>
                </Grid>
相关问题