【问题标题】:How to bind to certain property in a list of Model object? [duplicate]如何绑定到模型对象列表中的某些属性? [复制]
【发布时间】:2014-02-13 10:09:00
【问题描述】:

我有这个模型:

public class Device {
    public string Name { get; set; }
    public SomeOtherType SomeOtherStuff { get; set; }
}

还有这份清单:

ObservableCollection<Device> DevicesCollection { get; set; }

我不时更改。

我也使用了自定义的UserControl,这样:

<my:MyCustomListControl ItemsSource="{what goes here???}" />

此控件用法应该显示所有Devices 的列表,但只显示它们的Name 属性。

那么如何将ItemsSource 仅绑定到集合的Name 属性?

【问题讨论】:

标签: c# wpf xaml data-binding


【解决方案1】:

如果MyCustomListControl 继承自ItemsControl,您可以将DisplayMemberPath 设置为Name

<my:MyCustomListControl ItemsSource="{Binding DevicesCollection}"
                        DisplayMemberPath="Name" />

【讨论】:

    猜你喜欢
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 2019-08-23
    • 2014-12-04
    相关资源
    最近更新 更多