Search code examples
c#wpfcombobox

Get selected value from combo box in C# WPF


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.


Solution

  • 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();