I have a combobox, but I can only get a type of ComboxItem back so I never get the actual value (Tried "SelectedIt em" as well)
How do I get the selected value in string format to do the switch with?
XAML
and here is the code in the ViewModel
How do I get the selected value in string format to do the switch with?
XAML
Code:
<ComboBox
x:Name="cmbAllotment"
Grid.Row="1"
Margin="5,0,5,0"
Grid.Column="0"
SelectedValue="{Binding Path=AllotmentSelected, Mode=TwoWay}">
<ComboBoxItem Content="All (*)" IsSelected="True" />
<ComboBoxItem Content="Worcester" />
<ComboBoxItem Content="Rawsonville" />
<ComboBoxItem Content="De Doorns" />
<ComboBoxItem Content="Touwsrivier" />
</ComboBox>
Code:
private string allotmentSelected;
public string AllotmentSelected
{
get { return allotmentSelected; }
set
{
allotmentSelected = value;
//case statement to determine the selected allotment
if (allotmentSelected != null)
{
switch (allotmentSelected)
{
case "Worcester":
allotmentCode = "C0850004";
break;
case "Rawsonville":
allotmentCode = "C0850002";
break;
case "De Doorns":
allotmentCode = "C0850001";
break;
case "Touwsrivier":
allotmentCode = "C0850003";
break;
default:
allotmentCode = "*";
break;
}
}
OnNotifyPropertyChanged("AllotmentSelected");
}
}
Comment