【问题标题】:Using a Multiibinding inside a DataGrid Column in WPF在 WPF 中的 DataGrid 列中使用多重绑定
【发布时间】:2018-08-31 17:41:23
【问题描述】:

所以我将一个数据表绑定到我的网格,其中我有一些列,但基于两列我需要计算一个格式化值,如下例所示,我想显示一个 FullName = fname + " " + lname 使用转换器。我下面的 XAML 不起作用。当然,我想做一些更复杂的事情,只是在我的转换器中添加字符串。

                    <syncfusion:GridUnBoundColumn.ValueBinding>
                        <MultiBinding Converter="{StaticResource FullNameFormatingConverter}">
                            <MultiBinding.Bindings>
                                <Binding Path="fname" />
                                <Binding Path="lname" />
                            </MultiBinding.Bindings>
                        </MultiBinding>
                    </syncfusion:GridUnBoundColumn.ValueBinding>

如何在我的网格中实现建议的绑定?

【问题讨论】:

  • 我不熟悉 GridUnBoundColumn,但是您可能需要将绑定的 DataContext 设置为网格
  • DataContext 设置正确,其他列显示正确。我面临的问题是如何为多值转换器提供两个映射名称
  • 应用程序构建,其他一切都很好,但我的转换器不工作!尽管 fname 和 lname 也是网格绑定的数据表内的列,但此列 jsut 显示 System.DataRow... 文本.. 说我有 3 行,第一行有 fname = Jack 和 lname = Sparrow,我希望此列显示“Jack Sparrow”。我只是需要知道将这些列值正确提供给转换器的语法。
  • 你有没有考虑在MultiBinding中使用StringFormat,如图here
  • 在上述情况下,它不会在 y 转换器代码处中断。

标签: wpf xaml datatable binding datagrid


【解决方案1】:

您是否尝试使用Format 属性?

<syncfusion:GridUnBoundColumn Format="'{fname} {lname}'" />

或者GridTemplateColumnCellTemplate

<syncfusion:GridTemplateColumn.CellTemplate>
    <DataTemplate>
        <TextBlock>
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource FullNameFormatingConverter}">
                    <MultiBinding.Bindings>
                        <Binding Path="fname" />
                        <Binding Path="lname" />
                    </MultiBinding.Bindings>
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>

【讨论】:

  • 感谢这就像一个魅力!看起来问题出在使用syncfusion:GridUnBoundColumn,出于某种原因,它从未识别列映射。其他列有效!即使是 CellTemplate 也可以!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 2011-02-06
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 2018-07-28
  • 2010-12-16
相关资源
最近更新 更多