WPF Binding Collection To ComboBox and Selecting an item
Posted
by Adam Driscoll
on Stack Overflow
See other posts from Stack Overflow
or by Adam Driscoll
Published on 2008-11-22T03:22:31Z
Indexed on
2010/04/01
18:03 UTC
Read the original article
Hit count: 362
I've been knocking my head against this for some time now. I'm not really sure why it isn't working. I'm still pretty new to this whole WPF business.
Here's my XAML for the combobox
<ComboBox Width="200" SelectedValuePath="Type.FullName" SelectedItem="{Binding Path=Type}" Name="cmoBox" >
</ComboBox>
Here's what populates the ComboBox (myAssembly is a class I created with a list of possible types)
cmoBox.ItemsSource = myAssembly.PossibleTypes;
I set the DataContext in a parent element of the ComboBox in the code behind like this:
groupBox.DataContext = listBox.SelectedItem;
I want the binding to select the correct "possible type" from the combo box. It doesn't select anything. I have tried SelectedValue and SelectedItem. When I changed the DisplayMemberPath of the ComboBox to a different property it changed what was displayed so I know it's not completely broken.
Any ideas???
© Stack Overflow or respective owner