【发布时间】:2014-06-03 23:15:01
【问题描述】:
我有一个绑定到自定义类型的 ObservableCollection 的数据网格。该类型有一个布尔属性“IsCopying”。 “绑定”是通过将网格的 ItemSource 属性指定到 ObservableCollection 来完成的。
我想在数据绑定到网格之前更改数据。网格只需要是数据的只读视图。我已经使用 AutoGeneratingColumn 事件更改了列标题:
if (e.Column.header.ToString() == "IsCopying")
{
DataGridTextColumn t = new DataGridTextColumn();
t.header = "Status";
e.Column = t;
}
...效果很好。我想在将单个属性绑定到每行的单元格期间做同样的事情。我觉得它会像这样工作:
//NOT REAL CODE!!!!!!!
private void dgItem_CellBinding(object sender, DataGridCellBindingEventArgs e)
{
MyCustomType theItem = e.(MyCustomType)ObjectGettingBound;
if (theItem.IsCopying == true)
{
e.TypeGettingBound= DataGridCellType.Text //or however this works;
e.DataToBind = "Working...";
}else{
e.TypeGettingBound = DataGridCellType.Text;
e.DataToBind = "Waiting for command...";
}
}
希望以上内容有意义。我找不到单个单元格何时绑定以及如何拦截它的事件。我确信这很常见,但我对此很陌生,在 SO 上找不到任何解决这个特定问题的东西。也许我的方法不对?
【问题讨论】: