如何将动态数据绑定到UWP网格。 [英] How to bind the dynamic data to UWP grid.

查看:92
本文介绍了如何将动态数据绑定到UWP网格。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发UWP应用程序,我们需要动态创建列,并需要将动态数据绑定到网格。因此,我们需要在UWP网格中显示数据,如下所示。

We are developing the UWP application in which we need to create the columns dynamically and need to bind the dynamic data to the grid. So we need to display the data in the UWP grid as given below.

下面给出的类型定义,用于保存上述动态网格所需的数据。

The definitions of Types given below to hold the data required for the above dynamic grid.


   1。类型"属性"被定义为具有属性/行的名称及其对应的值。这基本上保留了一个单元格值。

  1. Type 'Property' is defined to have the name of the property/row and its corresponding value. This basically holds the one cell value.

 公共类物业

    {

        public string Name {get;组; }

 public class Property
    {
        public string Name { get; set; }

推荐答案

嗨Hari Kilari,

Hi Hari Kilari,

如果你想用动态显示表格数据,您应该可以使用

ListView
。我们可以将动态数据绑定到Listview。此外,我们应该能够在一个集合中设置日期。

If you want to show the table with dynamic data, you should be able to use ListView. And we can bind the dynamic data to the Listview. Also we should able to set the date in one collection.

例如:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ListView Name="MyListView">
        <ListView.HeaderTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Name" Width="200" />
                    <TextBlock  Text="Column1" Width="200" />
                    <TextBlock Text="Column2" Width="200" />
                    <TextBlock  Text="Column3" Width="200" />
                </StackPanel>
            </DataTemplate>
        </ListView.HeaderTemplate>
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name}" Width="200"></TextBlock>
                    <TextBlock Text="{Binding Column1}" Width="200"></TextBlock>
                    <TextBlock Text="{Binding Column2}" Width="200"></TextBlock>
                    <TextBlock Text="{Binding Column3}" Width="200"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</Grid>

代码背后:

public sealed partial class MainPage : Page
{
    private ObservableCollection<RolData> AllRowsData;

    public MainPage()
    {
        this.InitializeComponent();

        AllRowsData = new ObservableCollection<RolData> {
         new RolData("Row1", "11", "12", "13") ,   new RolData("Row2", "21", "22", "23"),new RolData("Row3", "31", "32", "33"),
         new RolData("Row4", "41", "42", "43"),   new RolData("Row5", "51", "52", "53"),   new RolData("Row6", "61", "62", "63")
        };
        MyListView.ItemsSource = AllRowsData;
    }
}

public class RolData
{
    private string name;

    public RolData(string name, string column1, string column2, string column3)
    {
        this.Name = name;
        this.Column1 = column1;
        this.Column2 = column2;
        this.Column3 = column3;
    }

    public string Name { get; set; }
    public string Column1 { get; set; }
    public string Column2 { get; set; }
    public string Column3 { get; set; }
}




最诚挚的问候,

Jayden Gu

Jayden Gu


这篇关于如何将动态数据绑定到UWP网格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆