我有一个 列表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);
}
然后我清除列表:
/* 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();