我想将二维数组int[,]
中的一些值绑定到网格中。阅读Two way binding between DataGrid and an array我下载.dll并添加引用。我的代码是:
XAML的一部分:
<Grid>
<dg2d:DataGrid2D Name="dataGrid2D" ItemsSource2D="{Binding Data2D}" Margin="0,0,0,130"/>
</Grid>
和c#背后:
public partial class MainWindow : Window
{
private int[,] _data2D;
public int[,] Data2D
{
get { return _data2D; }
set { _data2D = value; }
}
public MainWindow()
{
int[,] data2D = new int[5,5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
data2D[i, j] = 1;
}
}
_data2D = data2D
dataGrid2D.DataContext = this;
}
}
我也读过Binding 2d array with WPF DataGrid2D,但我不知道如何将它与我的问题联系起来?如何将MainWindow()与视图连接?有什么帮助吗?
答案 0 :(得分:0)
解决:
需要dataGrid2D.DataContext = this;