简体   繁体   English

带有静态列名的GridView表

[英]GridView Table with static column names

So I want to create a table like GridView control with static column names. 所以我想用静态列名创建一个像GridView控件这样的表。 I can add my grid columns or rows dynamicly with no problem via the ItemTemplate. 我可以动态地添加我的网格列或行,没有问题通过ItemTemplate。 The problem now is, when I try to add a static grid with columndefinitions to my GridView i cannot see it. 现在的问题是,当我尝试向我的GridView添加一个带有columndefinitions的静态网格时,我看不到它。 Do you know why? 你知道为什么吗?

here is my xaml code: (the grid which is not seen is marked) 这是我的xaml代码:(未标记的网格被标记)

<GridView Margin="10" Name="GridViewAllgemein" HorizontalAlignment="Center" VerticalAlignment="Center" ItemsSource="{x:Bind ausstattung}" BorderBrush="Black" IsTapEnabled="True" IsItemClickEnabled="True">
        <Grid Background="Red" Height="50"> //cannot see this grid
            <Grid.ColumnDefinitions> //cannot see this grid
                <ColumnDefinition Width="200"/> //cannot see this grid
                <ColumnDefinition Width="200"/> //cannot see this grid
                <ColumnDefinition Width="200"/> //cannot see this grid
                <ColumnDefinition Width="200"/> //cannot see this grid
            </Grid.ColumnDefinitions> //cannot see this grid
            <TextBlock Grid.Column="0" Text="Test"></TextBlock> //cannot see this grid
        </Grid> //cannot see this grid
        <GridView.ItemTemplate>
            <DataTemplate x:DataType="data:Ausstattung">
                <Grid Background="{ThemeResource SystemControlBackgroundAccentBrush}" Height="40" Margin="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="200"/>
                    </Grid.ColumnDefinitions>


                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0" Foreground="White" FontSize="14" Text="{x:Bind Beschreibung}" TextWrapping="Wrap"/>
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"  Grid.Column="1" Foreground="White" FontSize="14" Text="{x:Bind Ausgabedatum}" TextWrapping="Wrap"/>
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"  Grid.Column="2" Foreground="White" FontSize="14" Text="{x:Bind Rückgabedatum}" TextWrapping="Wrap"/>
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"  Grid.Column="3" Foreground="White" FontSize="14" Text="{x:Bind Anzahl}" TextWrapping="Wrap"/>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>

this is the result 结果就是这样 在此输入图像描述

The problem now is, when I try to add a static grid with columndefinitions to my GridView i cannot see it. 现在的问题是,当我尝试向我的GridView添加一个带有columndefinitions的静态网格时,我看不到它。 Do you know why? 你知道为什么吗?

This is because GridView is an ItemsControl and it cannot contain child elements directly. 这是因为GridView是一个ItemsControl,它不能直接包含子元素。

It must have items in its Items collection before it can show anything on the screen. 它必须在Items集合中有项目才能在屏幕上显示任何内容。 To populate the view, you can add items directly to the Items collection, or set the ItemsSource property to a data source. 要填充视图,可以直接将项添加到Items集合,或将ItemsSource属性设置为数据源。 See here 看到这里

As @Ipsit Gaur pointed out in a comment, in this case one option is to put the Grid with the Header before the GridView, since GridView itself does not have a contept for creating a Header. 正如@Ipsit Gaur在评论中指出的那样,在这种情况下,一个选项是在GridView之前将Grid与Header放在一起,因为GridView本身没有创建Header的语句。

Btw. 顺便说一句。 telerik opensourced its UWP controls and in some cases you can use it for free. telerik开源其UWP控件,在某些情况下,您可以免费使用它。 They have a Grid control with a built in functionality for this . 他们有一个Grid控件,内置了这个功能

Syncfusion also has a similar community licence with a similar control called SfDataGrid Syncfusion还具有类似的社区许可证, 具有类似的控件,称为SfDataGrid

*I'm not trying to advertise products, I just list free controls you can potentially use to solve your problem. *我不是在尝试宣传产品,我只列出了可以用来解决问题的免费控件。

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

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