2014-02-13 54 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" /> 
相關問題