Reputation: 4570
I know there is a few topics on this problem but haven't find any solutions to this problem I have..
I have a ViewModel with an observable collection and I want to bind this collection to a combo box. However, there is no selected item, no index, just the collection itself.
in the XAML I have
ComboBox ItemsSource="{Binding OSCollection}" DisplayMemberPath="OSCollection.Name"
I believe the trouble lies with the bold above, I want to get a property from the collection called name, but like I say - no item will be selected before the bind.
I could use a foreach or something to extract the properties from the collection but I don't think this is the MVVM and WPF way.
Any help would be grateful.
Thanks
Upvotes: 1
Views: 2279
Reputation: 2875
In addition to Sajeetharans comment:
When binding to a List of Type T
, DisplayMemberPath
will always refer to the Name of a Property
of T
. In your case it is only "Name"
Upvotes: 1
Reputation: 222722
DisplayMemberPath specifies the path to the display property.So it should be Name not OSCollection.Name
ComboBox ItemsSource="{Binding OSCollection}" DisplayMemberPath="Name"
Upvotes: 2