我遇到了 datagrid 和 DataGridCheckBoxClumn 的问题。首先我为数据网格项目创建结构:
public struct taxRateFromDatabase
{
public int rate { get; set; }
public string mark { get; set; }
public CheckBox c { get; set; }
}
之后在我的课堂上添加列、绑定等:
StackPanel tSp = new StackPanel();
DataGrid taxRateDataGrid = new DataGrid();
DataGridTextColumn col0 = new DataGridTextColumn();
DataGridTextColumn col1 = new DataGridTextColumn();
DataGridCheckBoxColumn col2 = new DataGridCheckBoxColumn();
Binding b = new Binding("checkBox");
b.Mode = BindingMode.TwoWay;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
taxRateDataGrid.Columns.Add(col0);
taxRateDataGrid.Columns.Add(col1);
taxRateDataGrid.Columns.Add(col2);
col0.Binding = new Binding("rate");
col1.Binding = new Binding("mark");
col2.Binding = b;
CheckBox c = new CheckBox();
c.Content = "a";
col0.Header = "Stawka";
col1.Header = "Oznaczenie";
col2.Header = "Status";
taxRateDataGrid.Items.Add(new taxRateFromDatabase { rate = 0, mark = "E", c = c });
taxRateDataGrid.Items.Add(new taxRateFromDatabase { rate = 1, mark = "G", c = c });
问题是我无法真正选中/取消选中我刚刚添加的复选框。我也尝试过在结构定义中没有复选框(只是空的datagridcheckboxcolumn),但这也不起作用。我在将返回数据网格的类中创建它,所以我不能真正访问 xaml。
任何建议将不胜感激;)