在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");
}
答案 0 :(得分:1)
sender
应该是点击的按钮,但也要看RoutedEventArgs.Source
和.OriginalSource
我还会考虑使用Command
和CommandParameter
来表明点击了哪个。