在 wpf 中找不到事件“SelectedIndexChanged”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28374316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Event "SelectedIndexChanged" is not found in wpf
提问by A nemati
in winform when i create a combobox i can found event "SelectedIndexChanged" the event work afterindex of combobox changed
在 winform 中,当我创建组合框时,我可以找到事件“SelectedIndexChanged”,该事件在组合框索引更改后起作用
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("after index change app show this MessageBox ");
}
but in wpf i cannot found event "SelectedIndexChanged" instead of i can found event "SelectionChanged" but i have a problem when is use it before index of combobox event work but i want to after index change show my code in event "SelectionChanged"
但是在 wpf 中我找不到事件“SelectedIndexChanged”而不是我可以找到事件“SelectionChanged”但是我在组合框事件索引工作之前使用它时遇到问题但我想在索引更改后在事件“SelectionChanged”中显示我的代码
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("before index change app show this MessageBox ");
}
what should i do . i want to show my MessageBox after i change index of my combobox
我该怎么办 。我想在更改组合框的索引后显示我的 MessageBox
sry for my poor english
可怜我可怜的英语
回答by Dmytro Chumachenko
Actually The event 'SelectionChanged' is called after index and value are changed you can check it simple
实际上,在更改索引和值后会调用事件“SelectionChanged”,您可以简单地检查一下
public partial class MainWindow : Window
{
private string[] _cmbxSource = new string[] {
"ZeroIndex",
"FirstIndex"
};
public MainWindow()
{
InitializeComponent();
cmbx.ItemsSource = _cmbxSource;
cmbx.SelectionChanged += cmbx_SelectionChanged;
}
void cmbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show(string.Format("Value and Index has been changed {0} {1}",
_cmbxSource[cmbx.SelectedIndex], cmbx.SelectedIndex));
}
}

