【问题标题】:WPF DataGrid Bind Editor Setting to another propertyWPF DataGrid 绑定编辑器设置到另一个属性
【发布时间】:2011-04-13 03:37:56
【问题描述】:

我在 DataGrid 中有一个字段,绑定到一个值 (Item.Amount),现在在该字段编辑器的样式中,我想将 Format 字段绑定到 Item.QuantityDecimalPoints。

但我似乎无法上树到记录绑定到的同一个项目。

我尝试了以下方法:

Format="{Binding Path=QuantityDecimalPoints, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DBO:Item}}}"

Format="{Binding Path=QuantityDecimalPoints, RelativeSource={RelativeSource PreviousData}}"

【问题讨论】:

    标签: wpf datagrid binding data-binding


    【解决方案1】:

    您需要绑定到 DataGridRow 的 DataContext 上的一个属性(它应该是同时包含 Amount 和 QuantityDecimalPoints 属性的项目)。你可以这样做:

    Format="{Binding DataContext.QuantityDecimalPoints, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 2014-05-30
      相关资源
      最近更新 更多