I have a combobox cmbOptions and a button btnShowItem
and here's the code:
private void btnShowItem_click(object sender, RoutedEventArgs e)
{
string item = ((ComboBoxItem)cmbOptions.SelectedItem).Content.ToString(); //Exception is here
}
Below is the exception:
System.InvalidCastException: "Unable to cast object of type 'System.String' to type 'System.Windows.Controls.ComboBoxItem'."
I've already gone through a number of links like these:
Cannot get ComboBox selected item value
ComboBox- SelectionChanged event has old value, not new value
Get selected value from combo box in c# wpf
etc, etc..
But didn't get the solution.
Please note I need to get the value of comboboxItem on buttonclick only NOT on cmbSelectionChange event