问题
I set the DisplayMemberPath
of a comboBox
as well as the ItemsSource
, now i'm trying to retrieve the selectedText
that is displayed but there is no selectedText
property. I tried
string s = comboBoxItem.SelectedItem.ToString();
but i'm getting a weird value. How do I retrieve the Displayed value of the comboBox
回答1:
For comboBox1
, in C# winforms, you can get the selected value with comboBox1.SelectedItem.ToString()
. In WPF (what apparently you want), you can get this information directly from the Content
property; you can access it by doing:
ComboBoxItem curItem = (ComboBoxItem)comboBox1.SelectedItem;
string selectedValue = curItem.Content.ToString();
来源:https://stackoverflow.com/questions/17628869/retrieve-display-value-of-combobox-winrt