【问题标题】:What would be the best option to display class properties in a Microsoft.Toolkit.Uwp.UI.Controls.DataGrid?在 Microsoft.Toolkit.Uwp.UI.Controls.DataGrid 中显示类属性的最佳选择是什么?
【发布时间】:2021-06-28 13:39:45
【问题描述】:

为了简化我的情况,基本上,我有以下从数据库中读取类型的类:

public class Type1
    {
        public int Property1 { get; set; }
        public int Property2 { get; set; }
    }

    public class Type2
    {
        public int Property3 { get; set; }
        public int Property4 { get; set; }
    }

    public class Info
    {
        public Type1 Type1 { get; set; }
        public Type2 Type2 { get; set; }
    }

我想做的是使用 Info 类在 DataGrid 中显示每个 Type 属性的名称和值。我应该选择什么方法来做到这一点?

我的想法是从 Info 类创建一个 DataTable 并将其用作 DataGrid 的输入。这会是最好的方法吗?

【问题讨论】:

  • 你能解释一下结果应该是什么样子吗?
  • 当然!结果表应具有以下列:Property1、Property2、Property3、Property4

标签: c# uwp datatable windows-community-toolkit


【解决方案1】:

是的,最好的方法是创建一个类,每个列都有一个属性(名称和值),您希望在 DataGrid 中显示该属性,然后根据您现有的类型数据创建此类的实例。

您应该将数据模型转换为 DataGrid 了解如何在屏幕上呈现的视图模型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 2017-02-13
    • 2019-06-23
    • 2016-06-19
    • 2010-10-30
    • 1970-01-01
    • 2011-08-07
    相关资源
    最近更新 更多