0

I have this model:

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

And this list:

ObservableCollection<Device> DevicesCollection { get; set; }

which I change from time to time.

I also use a custom UserControl I made, this way:

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

this control usage is supposed to shows a list of all Devices, but only their Name property.

So how do I bind the ItemsSource only to the Name property of the collection?

Tar
  • 8,529
  • 9
  • 56
  • 127
  • take a look at this question http://stackoverflow.com/questions/5409259/binding-itemssource-of-a-comboboxcolumn-in-wpf-datagrid – Ehsan Feb 13 '14 at 10:14

1 Answers1

1

In case MyCustomListControl is inheriting from ItemsControl, you can set DisplayMemberPath to Name.

<my:MyCustomListControl ItemsSource="{Binding DevicesCollection}"
                        DisplayMemberPath="Name" />
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185