Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式将DataGrid绑定到列表数组_C#_Wpf_Data Binding - Fatal编程技术网

C# 以编程方式将DataGrid绑定到列表数组

C# 以编程方式将DataGrid绑定到列表数组,c#,wpf,data-binding,C#,Wpf,Data Binding,我必须列出以下数据: List<string[]> dataRow = new List<string[]>(); 但我有一个“ContextSwitchDeadlock”错误。我怎样才能解决这个问题 谢谢你的帮助 编辑:已解决,但未使用数据绑定方式 我是这样解决的: List<string> ColumnName = new List<string>(); List<string[]> dataRow = new List<s

我必须列出以下数据:

List<string[]> dataRow = new List<string[]>();
但我有一个“ContextSwitchDeadlock”错误。我怎样才能解决这个问题

谢谢你的帮助

编辑:已解决,但未使用数据绑定方式

我是这样解决的:

List<string> ColumnName = new List<string>();
List<string[]> dataRow = new List<string[]>();
DataTable myTable = new DataTable();

 // Fill Array ColumnName and dataRow Here

foreach (string text in ColumnName)
{
   myTable.Columns.Add(text);
}
foreach (string[] cellContent in dataRow)
{
   myTable.Rows.Add(cellContent);
}
DatensatzGrid.ItemsSource = myTable.AsDataView();
List ColumnName=新列表();
List dataRow=新列表();
DataTable myTable=新DataTable();
//在此处填充数组ColumnName和dataRow
foreach(ColumnName中的字符串文本)
{
myTable.Columns.Add(文本);
}
foreach(数据行中的字符串[]cellContent)
{
myTable.Rows.Add(cellContent);
}
DatensatzGrid.ItemsSource=myTable.AsDataView();

谢谢你的回复

DataGrid
控件不支持绑定到2D数组、
列表>

见这个问题:

不久前,我创建了一个子类
DataGrid
()来实现这一点

要使用它,只需添加对DataGrid2DLibrary.dll的引用,请添加此命名空间

xmlns:dg2d="clr-namespace:DataGrid2DLibrary;assembly=DataGrid2DLibrary"
然后创建DataGrid2D并将其绑定到IList、2D数组或1D数组,如下所示

<dg2d:DataGrid2D Name="MyDataGrid"
                 ItemsSource2D="{Binding DataRow}"/>

解决方案中没有数据绑定的行
MyDataGrid.ItemsSource=MyDataGrid
尝试实现什么。好的!我不是一个profi,而是这个工作!你能解释你的想法吗?使用我的解决方案,我们可以将其转换为数据绑定吗?谢谢你
xmlns:dg2d="clr-namespace:DataGrid2DLibrary;assembly=DataGrid2DLibrary"
<dg2d:DataGrid2D Name="MyDataGrid"
                 ItemsSource2D="{Binding DataRow}"/>
MyDataGrid.ItemsSource2D = dataRow;