Retrieve display value of combobox winrt

牧云@^-^@ 提交于 2019-12-11 06:06:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!