Get selected value from combo box in C# WPF

Boardy picture Boardy · Dec 4, 2010 · Viewed 342.7k times · Source

I have just started using WPF forms instead of Windows Forms forms. In a Windows Forms form I could just do:

ComboBox.SelectedValue.toString();

And this would work fine.

How do I do this in WPF? It doesn't seem to have the option.

Answer

Boardy picture Boardy · Dec 4, 2010

I have figured it out a bit of a strange way of doing it compared to the old WF forms:

ComboBoxItem typeItem = (ComboBoxItem)cboType.SelectedItem;
string value = typeItem.Content.ToString();