如何将click事件添加到我的按钮数组中?
我只需要一次点击事件,每个按钮的工作方式都相同。
ButtonArray[i] = new Button();
ButtonArray[i].Margin = new Thickness(horizontal, vertical, 0, 0);
LayoutRoot.Children.Add(ButtonArray[i]);
ButtonArray[i].Height = buttonsize;
ButtonArray[i].Width = buttonsize;
ButtonArray[i].Background = brush;
ButtonArray[i].VerticalAlignment = VerticalAlignment.Top;
ButtonArray[i].HorizontalAlignment = HorizontalAlignment.Left;
答案 0 :(得分:1)
像这样:
ButtonArray[i].Click += ButtonArray_Click;
然后:
void ButtonArray_Click(object sender, RoutedEventArgs e)
{
//Do your stuff
}