简体   繁体   English

WPF DataGrid,如何将 class 属性绑定为行?

[英]WPF DataGrid, How to binding class properties as row?

Model type is: Model 类型是:

// Model
public class MyClass
{
    int A1 { get; set; }
    int A2 { get; set; }
    int A3 { get; set; }
    double B1 { get; set; }
    double B2 { get; set; }
    double B3 { get; set; }
}

...

private MyClass myClass1;
// Binding Source in ViewModel
public MyClass MyClass1
{
    Get => myClass1;
    Set => SetProperty(ref myClass1, value);
}

I want to bind the properties of MyClass to each row.我想将 MyClass 的属性绑定到每一行。 MyClass1 property instance changes frequently. MyClass1 属性实例经常变化。

Name名称 Value价值
A1 A1 123 123
A2 A2 456 456
A3 A3 789 789
B1 B1 0.0 0.0
B2 B2 1.1 1.1
B3 B3 2.2 2.2

In View, it will look like above, and Value Column is editable.在 View 中,它看起来像上图,并且 Value Column 是可编辑的。 Values edited in the View are updated directly via binding.在视图中编辑的值通过绑定直接更新。 How should I implement the View in this case?在这种情况下我应该如何实现视图? 3rd party libraries cannot be used.不能使用第 3 方库。

You could use a PropertyGrid for this.您可以为此使用 PropertyGrid。 If your software is for non commercial use you could use the PorpertyGrid from Xceed for example.例如,如果您的软件用于非商业用途,您可以使用Xceed 的 PorpertyGrid

The WPF would look like <xctk:PropertyGrid SelectedObject="{Binding MyClass}"/> . WPF 看起来像<xctk:PropertyGrid SelectedObject="{Binding MyClass}"/> As seen in the link the control is highly ajustable.如链接中所示,控件是高度可调的。

在此处输入图像描述

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

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