【问题标题】:Bind Property Of the ViewModel to CurrentCell将 ViewModel 的属性绑定到 CurrentCell
【发布时间】:2013-02-17 12:01:21
【问题描述】:

我使用WPF DataGrid

我想bindCurrentCell(已编辑的单元格)的文本与我在 myViewModel 中的属性一起使用

可以这样做吗?

编辑:

我试试这个方法:

 <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')

【问题讨论】:

    标签: wpf mvvm binding datagrid


    【解决方案1】:

    我不确定我是否正确理解了您的问题。 但是您是否考虑过创建一个带有标签的 DataTemplate 并将其 content 属性绑定到 viewmodel 属性

    【讨论】:

    • 是的,问题是我想将属性绑定到当前编辑单元格
    • 你试过这样吗?
    • 它绑定到所有datagridtextcolumn而不是当前编辑列
    【解决方案2】:

    好的,这样就成功了:

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

    【讨论】:

      猜你喜欢
      • 2011-08-26
      • 1970-01-01
      • 2017-08-08
      • 2015-01-25
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      相关资源
      最近更新 更多