如何为单击文本框,复选框和组合框创建事件,并对所有这些事件使用相同的事件处理程序?
答案 0 :(得分:0)
根据您的意愿,例如可以处理PreviewMouseLeftButtonDown
事件:
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement fe = (FrameworkElement)sender;
MessageBox.Show(fe.Name);
}
示例XAML:
<TextBox x:Name="a" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown" />
<CheckBox x:Name="b" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown" />
<ComboBox x:Name="c" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
<ComboBoxItem>1</ComboBoxItem>
</ComboBox>