本文介绍了如何获得与"Content"不同的ComboBoxItem值.价值 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在WPF中有一个ComboBox,其中有两个ComboBoxItem.
我想从每个与"Content"属性不同的ComboBoxItem中获取一个不同的值.
在HTML中,就像:
Hi, I have a ComboBox in WPF with two ComboBoxItem.
I want to get a different value from each ComboBoxItem that''s different from ''Content'' property.
In HTML, it''s like :
<select name="test" id="test">
<option value="valueReturned1">Choice number one displayed</option>
<option value="valueReturned2">Choice number two displayed</option>
</select>
我的XAML是:
My XAML is :
<ComboBox x:Name="cbStat">
<ComboBoxItem Content="item one displayed"></ComboBoxItem>
<ComboBoxItem Content="item two displayed"></ComboBoxItem>
</ComboBox>
我在将ComboBoxItems中放入值"时需要做些什么,当我选择一个项目时可以得到该值? (就像在HTML中一样,我获得了值"属性.
我在ComboBoxItem中搜索了值"属性,但未找到:(
预先感谢您的帮助.
What I have to do for put a ''value'' in my ComboBoxItems that i can will get when i select an item ? (like in HTML i get the ''value'' property.
I have search for a ''value'' property in the ComboBoxItem but not found :(
Thanks by advance for help.
推荐答案
<combobox x:name="nameSelectionTypeStat" height="24" xmlns:x="#unknown">
VerticalAlignment="Center" MinWidth="75">
<comboboxitem content="Stats. au trimestre"></comboboxitem>
<comboboxitem content="Stats. à l'année"></comboboxitem>
</combobox>
<Button x:Name="nameValiderTypeStat" Content="Valider le type" Height="24"
VerticalAlignment="Center" Click="nameValiderTypeStat_Click_1" />
CodeBehind:
CodeBehind :
private void nameValiderTypeStat_Click_1(object sender, RoutedEventArgs e)
{
if (nameSelectionTypeStat.SelectedIndex == 0)
{
MessageBox.Show("Choice 1");
}
else if (nameSelectionTypeStat.SelectedIndex == 1)
{
MessageBox.Show("Choice 2");
}
}
这篇关于如何获得与"Content"不同的ComboBoxItem值.价值 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!