How do I get the selected value (eg Option1
) as a string
from my example below. I've tried loads of suggestions on Google but can't get the string.
XAML:
<ComboBox x:Name="selectOption" Text="Select Option"
SelectionChanged="selectOption_SelectionChanged"
SelectedValue="{Binding VMselectedOption, Mode=TwoWay}" >
<ComboBoxItem Name="cbb1">Option1</ComboBoxItem>
<ComboBoxItem Name="cbb2">Option2</ComboBoxItem>
<ComboBoxItem Name="cbb3">Option3</ComboBoxItem>
</ComboBox>
codebehind:
private void selectOption_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedValue = selectOption.SelectedValue;
}
//elsewhere in code
var test = viewModel.VMselectedOption;
Both selectedValue and test return the string "System.Windows.Controls.ComboBoxItem: Option1" and not "Option1"
This should be really simple but I just cannot get this working or see what is wrong?