本文介绍了Silverlight:如何在组合框中选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个带有Silverlight中静态数据的ComboBox.我的代码如下:
Hello all,
I have a ComboBox with static data in silverlight. My code is as follows:
<ComboBox Grid.Column="1" Grid.Row="4" Height="23" HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" Width="120">
<ComboBox.Items>
<ComboBoxItem Content="ASX_D"></ComboBoxItem>
<ComboBoxItem Content="FOREX_D"></ComboBoxItem>
<ComboBoxItem Content="FOREX_H"></ComboBoxItem>
<ComboBoxItem Content="FUTERE_H"></ComboBoxItem>
<ComboBoxItem Content="FUTURE_D"></ComboBoxItem>
<ComboBoxItem Content="TRADE_H"></ComboBoxItem>
</ComboBox.Items>
</ComboBox>
我想在单击按钮时从组合框中选择selecteditem.
我正在使用:
I want to pick the selecteditem from combobox on a button click.
i am using:
string st=comboBox1.SelectedItem.ToString();
但它返回System.Windows.Controls.ComboBoxItem
请向我建议如何选择组合框的选定项目.
非常感谢您的帮助.
but it return System.Windows.Controls.ComboBoxItem
Please suggest to me how to pick the selected items of a combobox.
Any help is greatly appreciated.
推荐答案
string st = ((ComboBoxItem)comboBox1.SelectedItem).Content.ToString();
var itemType = MyCombBox.SelectedItem.GetType();
var pi = itemType.GetProperty(MyCombBox.DisplayMemberPath);
var stringValue = pi.GetValue(MyCombBox.SelectedItem, null).ToString();
这篇关于Silverlight:如何在组合框中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!