【问题标题】:CheckComboBox: how do i display the list of selected items?CheckComboBox:如何显示所选项目的列表?
【发布时间】:2015-05-13 20:20:29
【问题描述】:

我正在使用Extended WPF Toolkit's CheckComboBox。绑定工作正常。使用自定义ItemTemplate 时,如何显示选定的名称 简 - 老师,约翰 - 开发人员,乔 - 护士 在Text 属性中?将DisplayMemberPathItemTemplate 一起使用不起作用。

<xctk:CheckComboBox ItemsSource="{ Binding Path=Customers }" Delimiter="," 
                    ValueMemberPath="Id" SelectedValue="{ Binding SelectedCustomerIds }" 
                    ItemTemplate="{ StaticResource ccBTemplate }" />​

<DataTemplate x:Key="ccBTemplate ">
  <TextBlock Text="{ Binding Path=Name }" />
  <TextBlock Text="{ Binding Path=JobTitle }" />
</DataTemplate>

【问题讨论】:

  • 您能否提供更多信息,说明您的对象结构在数据方面是什么样的?
  • 不完全确定the selected items is not displayed in the checkcombobox like it was while using displaymemberpath 的意思。你到底看到了什么?
  • 将 DisplayMemberPath 添加到&lt;xctk:CheckComboBox DisplayMemberPath="Name" .../&gt;

标签: wpf xaml datatemplate


【解决方案1】:

Text 属性获取所有SelectedItems,通过调用ToString() 将它们转换为文本,最后将它们与Delimiter 连接起来。

所以您只需要在您的客户类上覆盖ToString(),如下所示

public override string ToString
{
    return Name + " - " + Job;
}

【讨论】:

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