Get selected value from combo box in C# WPF

后端 未结 21 673
粉色の甜心
粉色の甜心 2020-12-08 09:29

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

ComboBox.SelectedValue.toString();
21条回答
  •  佛祖请我去吃肉
    2020-12-08 10:09

    My XAML is as below:

    
        
        
        
    
    

    The content is showing as text and the name of the WPF combobox. To get the name of the selected item, I have follow this line of code:

    ComboBoxItem ComboItem = (ComboBoxItem)cmbDeviceDefinitionId.SelectedItem;
    string name = ComboItem.Name;
    

    To get the selected text of a WPF combobox:

    string name = cmbDeviceDefinitionId.SelectionBoxItem.ToString();
    

提交回复
热议问题