2014-02-13 44 views
0

我有这样的模式:如何绑定到Model对象列表中的某个属性?

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???}" /> 

此控件的使用应该显示所有Device s的列表,但只有他们Name财产。

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

+0

看看这个问题http://stackoverflow.com/questions/5409259/binding-itemssource-of-a-comboboxcolumn-in-wpf-datagrid – Ehsan

回答

1

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

<my:MyCustomListControl ItemsSource="{Binding DevicesCollection}" 
         DisplayMemberPath="Name" /> 
相关问题