I have a list of Button
, and I add an event handler for each button:
List<Button> buttons = new List<Button>();
for (int i = 0; i < 10; i++)
{
Button btn = new Button();
btn.Click = new RoutedEventHandler(OnbtnClick);
buttons.Add(btn);
}
Then I clear the list:
/* Have I to remove all events here (before cleaning the list), or not?
foreach (Button btn in buttons)
btn.Click -= new RoutedEventHandler(OnbtnClick);
*/
buttons.Clear();