I’ve got a ComboBox with an ItemsSource which I’ve bound to a List(Of String).
What I’d like to do is have the XAML update a String property when the SelectedValue of the ComboBox changes. I’ve seen a whole bunch of examples for TextBoxes which use
Text="{Binding Path=MyString}"
sort of stuff, but I don’t really think that’ll be the way to go if, in future, I need to change the ItemsSource to a List(Of ObscureObject)…
Binding to the selected property of a combobox is fairly simple.
XAML :
CodeBehind :
If you want to insert text into the selected item, you’ll need to use
INotifyPropertyChangedas for your scalability issue, its a fairly minor change to update the type of a property to reflect a collection. Otherwise you could try binding to an
Objectalthough that would mean you would constantly have to recast the object back to the state you want.