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