C#WPF,ListView和GridView,动态列以及数据绑定问题

问题描述 投票:-1回答:1

我有一个自定义类:

public class myField {
    public string MyName;
    public string MyDataType;
    public Field details;
}

自定义类“Field”是从导入的Salesforce.com Partner WSDL定义的。它看起来像这样:

public class Field {
    public string name;
    public string label;
    public string type;
    public int length;
    public bool custom;
    ... // there are probably 50+ defined properties here
}

我创建了一个myField对象列表,以保存这些字段的列表:

public List<myField> MasterList = new List<myField>();

这个列表是通过一些API调用填充的,我已经验证了数据是否存在且不为空。

我的目标是在ListView中显示字段“MyName”,“MyDataType”以及“details”字段下的所有子属性。

public GridView myGridView = new GridView();
GridViewColumn theColumn;

theColumn = new GridViewColumn();
theColumn.Header = "MyName";
theColumn.DisplayMemberBinding = new Binding("MyName");
myGridView.Columns.Add(theColumn);

theColumn = new GridViewColumn();
theColumn.Header = "length";
theColumn.DisplayMemberBinding = new Binding("details.length");
myGridView.Columns.Add(theColumn);

myListView.View = myGridView;
myListView.ItemsSource = MasterList;

我遇到的问题是,我尝试显示的任何主要属性工作正常(MyName,MyDataType),但任何子属性(我通过“详细信息”字段拉出的子字段)根本不显示(名称,标签,类型,长度,定制等)。

binding = "MyName" // displays correctly
binding = "MyDataType" // displays correctly
binding = "details.name" // does not display correctly
binding = "details.label" // does not display correctly
etc

有谁知道如何解决这个问题?

c# wpf class listview gridview
1个回答
0
投票

我复制了你的代码甚至MyNameMyDataType都无法显示,除非我将它们改为以下

public class myField {
    public string MyName {get; set;}
    public string MyDataType {get; set;}
    public Field details {get; set;}
}

public class Field {
    public string name {get; set;}
    public string label {get; set;}
    public string type {get; set;}
    public int length {get; set;}
    public bool custom {get; set;}
}

一切都运转正常

© www.soinside.com 2019 - 2024. All rights reserved.