【问题标题】:Silverlight: how to set combobox DisplayMemberPath with multiple properties from a listSilverlight:如何使用列表中的多个属性设置组合框 DisplayMemberPath
【发布时间】:2011-07-30 16:58:58
【问题描述】:

我有一个具有 Id、UserName、FirstName 和 LastName 等属性的用户列表。

我将如何设置组合框的显示以显示“姓氏,名字”,所以在组合框上它将显示为“Doe,John”。

【问题讨论】:

    标签: c# silverlight silverlight-4.0 mvvm


    【解决方案1】:

    您可以使用 ItemTemplate 在 UI 上显示模型对象的任意属性(对于本示例,Firstname 和 Lastnames):

    <local:ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Margin="0,3,0,3">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Firstname}" />
                    <TextBlock Text="{Binding Path=Lastname}" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </local:ComboBox.ItemTemplate>
    

    【讨论】:

      猜你喜欢
      • 2019-04-30
      • 2017-06-26
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      相关资源
      最近更新 更多