本文介绍了事件“SelectedIndexChanged"在 wpf 中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 winform 中,当我创建一个组合框时,我可以找到事件SelectedIndexChanged"事件工作组合框索引改变后

in winform when i create a combobox i can found event "SelectedIndexChanged"the event work after index of combobox changed

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MessageBox.Show("after index change app show this MessageBox ");
    }

但在 wpf 中我找不到事件SelectedIndexChanged"而不是我可以找到事件SelectionChanged"但是我在组合框事件索引之前使用它时遇到问题,但我想在索引更改后在事件SelectionChanged"中显示我的代码

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"

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        MessageBox.Show("before index change app show this MessageBox ");
    }

我该怎么办.我想在更改组合框索引后显示我的 MessageBox

what should i do . i want to show my MessageBox after i change index of my combobox

为我糟糕的英语感到抱歉

sry for my poor english

推荐答案

其实 'SelectionChanged' 事件是在 index 和 value 改变后调用的,你可以简单检查一下

Actually The event 'SelectionChanged' is called after index and value are changed you can check it simple

    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));
    }
}

这篇关于事件“SelectedIndexChanged"在 wpf 中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:37