从 C# WPF 的组合框中获取选定的值 [英] Get selected value from combo box in C# WPF
本文介绍了从 C# WPF 的组合框中获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始使用 WPF 表单而不是 Windows 表单.在 Windows 窗体中,我可以这样做:
I have just started using WPF forms instead of Windows Forms forms. In a Windows Forms form I could just do:
ComboBox.SelectedValue.toString();
这样就可以了.
如何在 WPF 中执行此操作?好像没有这个选项.
How do I do this in WPF? It doesn't seem to have the option.
推荐答案
与旧的 WF 形式相比,我发现了一个有点奇怪的方法:
I have figured it out a bit of a strange way of doing it compared to the old WF forms:
ComboBoxItem typeItem = (ComboBoxItem)cboType.SelectedItem;
string value = typeItem.Content.ToString();
这篇关于从 C# WPF 的组合框中获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文