c# - What would be the best option to display class properties in a Microsoft.Toolkit.Uwp.UI.Controls.DataGrid?
问题描述
Simplifying my case, basically, I have the following classes where Types are read from a DB:
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; }
}
What I would like to do, is display the name and value of each Type property in a DataGrid using the Info class. What approach should I choose to do this?
My idea was to create a DataTable from the Info class and use that as an input for the DataGrid. Would this be the best approach?
解决方案
Yes, the best approach would be to create a class with a property per column (name and value) that you want to display in the DataGrid
and then create instances of this class based on your existing type data.
You should transform your data model into a view model that the DataGrid
understands how to present on the screen.
推荐阅读
- nest-device-access - 设备访问速率限制
- javascript - JavaScript if 语句在函数内部不起作用。谁知道怎么修它?
- mysql - 如何删除与删除的表关联的用户权限?
- python - 在 Dockerfile 中安装包时出错(使用 cron 运行 pythoscript)
- python - 根据多个数据帧的公共时间戳创建数据帧
- mysql - 来自多个和/或新 .CSV 文件的简单更新表
- excel - 如何使用 VBA 宏从一个工作表复制“特定”行并粘贴到另一个工作表中
- python - 如何让这个类接受整数列表/元组作为参数?
- sql - Access SQL比较在查询中不为空
- c++ - std::variant 类型的向量到 std::tuple