如何在同一事件点击中区分两个不同的按钮?

时间:2017-05-31 23:30:16

标签: c# .net wpf

在WPF上,如果我只有一个按钮点击事件共享两个或更多(52更精确),有没有办法区分事件来自哪个按钮?

 private void Button_Card_Click(object sender, RoutedEventArgs e)
        {
            // for testing
            // it works for each button, but which one has been clicked?
            MessageBox.Show("Clicked");
        }

First button object with event set up

Second button object with event set up

1 个答案:

答案 0 :(得分:1)

sender应该是点击的按钮,但也要看RoutedEventArgs.Source.OriginalSource

我还会考虑使用CommandCommandParameter来表明点击了哪个。