Wpf MVVM绑定列表<;列表<;字符串>&燃气轮机;到数据网格

Wpf MVVM绑定列表<;列表<;字符串>&燃气轮机;到数据网格,wpf,binding,Wpf,Binding,我想将模型的属性绑定到datagrid,但我做不到 我在模型中有属性 模型包含带有字符串列表的列表 列表中的行数是常量 public class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtua

我想将模型的属性绑定到datagrid,但我做不到 我在模型中有属性 模型包含带有字符串列表的列表 列表中的行数是常量

public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class TestViewModel : ViewModelBase
    {
        public TestViewModel()
            : this(new FileService())
        {
        }

        public TestViewModel(IFileService fileService)
        {

            var list = new List<List<string>>();
            list.Add(new List<string>() { "1", "2", "3" });
            list.Add(new List<string>() { "3", "4", "5" });
            RecodListFromCsv = list;
        }

        private List<List<string>> _RecodListFromCsv;

        public List<List<string>> RecodListFromCsv
        {
            get { return _RecodListFromCsv; }
            set
            {
                if (_RecodListFromCsv != value)
                {
                    _RecodListFromCsv = value;
                    OnPropertyChanged("RecodListFromCsv");
                }
            }
        }
    }
公共类ViewModelBase:INotifyPropertyChanged
{
公共事件属性更改事件处理程序属性更改;
[NotifyPropertyChangedInvocator]
受保护的虚拟void OnPropertyChanged([CallerMemberName]字符串propertyName=null)
{
PropertyChangedEventHandler处理程序=PropertyChanged;
if(handler!=null)handler(这是新的PropertyChangedEventArgs(propertyName));
}
}
公共类TestViewModel:ViewModelBase
{
公共TestViewModel()
:此(新文件服务())
{
}
公共TestViewModel(IFileService文件服务)
{
var list=新列表();
添加(新列表(){“1”、“2”、“3”});
添加(新列表(){“3”、“4”、“5”});
RecodListFromCsv=列表;
}
私有列表_RecodListFromCsv;
从CSV记录的公共列表
{
获取{return\u recodlistfromsv;}
设置
{
如果(_recodlistfromcvs!=值)
{
_RecodListFromCsv=值;
OnPropertyChanged(“RecodListFromCsv”);
}
}
}
}
xaml


和UI显示


我做错了什么。如何操作?

datagrid的每一行项目都是
列表的类型
因此datagrid的自动生成列将生成
列表
对象(容量、计数)的公共属性!。因此,如果您的项目编号为3,请快速解决此问题,而不是使用
List

var list = new List<Tuple<string,string,string>>();
list.Add(new Tuple<string,string,string>() { "1", "2", "3" });
list.Add(new Tuple<string,string,string>() { "3", "4", "5" });
RecodListFromCsv = list;
var list=newlist();
添加(新元组(){“1”、“2”、“3”});
添加(新元组(){“3”、“4”、“5”});
RecodListFromCsv=列表;
稳定的解决方案是创建一个持久类,并正确地创建该对象类的列表

var list = new List<Tuple<string,string,string>>();
list.Add(new Tuple<string,string,string>() { "1", "2", "3" });
list.Add(new Tuple<string,string,string>() { "3", "4", "5" });
RecodListFromCsv = list;