【问题标题】:如何仅在一个 DataGrid-Cell 中动态显示列表/数组?
【发布时间】:2022-01-23 12:40:19
【问题描述】:

我有一个带有模型列表的 RefItem。我现在想在一个 DataGrid-Cell 中显示每个模型的描述属性,如下所示:

35 小时、10 小时、3 小时

我首先想到了一个转换器,但是C#需要一个IValueConverter,而对象参数只有一个字符串,理论上需要一个IMultiValueConverter。

我的 DataGrid-Cell 如下所示:

<DataGridTextColumn x:Name="txtScopeOfCare" Header="Scope of Care" 
IsReadOnly="true" Binding="{Binding Path=CareModel.Description}" />

当然,这个Binding不起作用,因为它是一个列表。 有人知道如何实现这一目标吗? :)

【问题讨论】:

  • 你能用 String.Join(",", CareModel.Description) 吗?

标签: c# wpf xaml


【解决方案1】:

为什么不直接创建另一个属性并绑定到它?

public string Description => string.Join(",", CareModel.Select(c => c.Description));

<DataGridTextColumn x:Name="txtScopeOfCare" Header="Scope of Care" 
IsReadOnly="true" Binding="{Binding Path=Description, Mode=OneTime}" />

我不确定你指的是什么a list,如果Description 是列表,你可以这样做:

public string Description => string.Join(",", CareModel.Description);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 2020-07-05
    • 2011-01-03
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多