Silverlight - how do I get the text of the selected item in a combobox
The selected item of your combo box is whatever type of item is currently holding. So if you set the binding to a collection of strings, then the selected item will be a string:
string mySelectedValue = ((string)MyComboBox.SelectedItem);
If it is a more complex object you will need to cast and use the expected object. If you have XAML using the list box item class, like:
<ComboBox x:Name="MyComboBox">
<ComboBox.Items>
<ComboBoxItem>
<TextBlock Text="Hello World"/>
</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
Then you would access the selected item like this:
string mySelectedValue =
((TextBlock)((ComboBoxItem)MyComboBox.SelectedItem).Content).Text;
Right, the answer is to use myCombo.SelectionBoxItem.ToString()
For a complex object, use reflection with the DisplayMemberPath property:
var itemType = cbx.SelectedItem.GetType();
var pi = itemType.GetProperty(cbx.DisplayMemberPath);
var stringValue = pi.GetValue(cbx.SelectedItem, null).ToString();