I have multiple buttons instead of doing
this.button1.Click += new System.EventHandler(this.button_Click);
this.button2.Click += new System.EventHandler(this
Instead of making button1
, button2
etc, make a List of buttons.
Then you can write:
myList.ForEach( b => b.Click += button_Click );
From XAML you can attach the click handler to the parent of the buttons something like this (I use a StackPanel as an example):
This works because the buttons Click event is a bubbling routed event.