UWP - 向我的 gridview 添加标题行

我对通用 Windows 平台应用程序非常陌生,我正在尝试在 XAML 中设计表单/页面。

我设法创建了一个 GridView,它绑定到一个包含数据的类,这些数据都很好用,但我不知道如何向我的列添加标题。


在添加绑定数据行之前,是否需要在顶部添加一行?


任何帮助都会很棒。


XAML 代码:


    <Grid.RowDefinitions>

        <RowDefinition Height="*" />

        <RowDefinition Height="100" />

    </Grid.RowDefinitions>

    <GridView ItemsSource="{x:Bind data}" IsItemClickEnabled="True">

        <GridView.ItemTemplate>

            <DataTemplate x:DataType="local:DataStructure">


                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">

                            <TextBlock FontSize="18" Text="{x:Bind ItemNumber}" HorizontalAlignment="Right" Margin="0,0,20,0" ></TextBlock>

                            <TextBlock FontSize="18" Text="{x:Bind ItemDetails}" HorizontalAlignment="Right"></TextBlock>

                            <CheckBox IsChecked="{x:Bind YesNo}"></CheckBox>

                            <CheckBox IsChecked="{x:Bind NotApplicable}"></CheckBox>

                        </StackPanel>


            </DataTemplate>

        </GridView.ItemTemplate>

    </GridView>

    <TextBlock Grid.Row="1" Name="ResultTextBlock" FontSize="24" Foreground="Red" FontWeight="Bold" />

</Grid>


浮云间
浏览 223回答 1
1回答

幕布斯7119047

您是否尝试在 Header 属性中添加 Grid ?<GridView>&nbsp; &nbsp; &nbsp; &nbsp; <GridView.Header>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="*"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="*"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="Header 1" Grid.Column="0"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="Header 2" Grid.Column="1"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Grid>&nbsp; &nbsp; &nbsp; &nbsp; </GridView.Header>&nbsp; &nbsp; &nbsp; &nbsp; <GridView.Items>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <GridViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="Item 1"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </GridViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <GridViewItem>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="Item 2"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </GridViewItem>&nbsp; &nbsp; &nbsp; &nbsp; </GridView.Items>&nbsp; &nbsp; </GridView>当然,您需要做一些工作来将列标题与项目对齐,但这可能是一种方法。查看其他有用属性的文档,例如HeaderTemplate.
打开App,查看更多内容
随时随地看视频慕课网APP