将ViewModel的属性绑定到CurrentCell

时间:2013-02-17 12:01:21

标签: wpf mvvm binding datagrid

我使用WPF DataGrid

我希望bind CurrentCell(已修改的单元格)的文字包含我ViewModel

中的属性

可以这样做吗?

修改

我这样试试:

 <DataGrid CurrentCell="{Binding MyProp}"...../>

我收到此错误:

Value produced by BindingExpression is not valid for target property.; Value='<null>' BindingExpression:Path=MyProp; DataItem='MyViewModel' (HashCode=38365672); target element is 'DataGrid' (Name='CustomCmdDg'); target property is 'CurrentCell' (type 'DataGridCellInfo')

2 个答案:

答案 0 :(得分:0)

我不确定我理解你的问题是对的。 但您是否考虑使用标签创建DataTemplate并将其content属性绑定到viewmodel属性

答案 1 :(得分:0)

好吧,它以这种方式成功:

<DataGrid CurrentCell="{Binding MyProp, Mode=OneWayToSource}"...../>
相关问题