在代码中用for循环new出了若干个button,这些button共用一个事件Img_Click,
但现在我用Img_Click能够实现多个事件的switch,请问各位大侠请问这个参数怎么传递?
代码如下:
private void Img_Click(object sender, RoutedEventArgs e) {
Button btn = (Button)sender;
DetailsImage(CrossRoadState.南丁字路口.ToString());
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
DataGridIntro.CrossingArray _CrossingArray = new DataGridIntro.CrossingArray();
int index = Convert.ToInt32(cmb.SelectedValue)-1;
if (index >= _CrossingArray.Count || index == -2) return;
CrossRoadPixture.Children.Clear();
for (int i = 0; i < Ceiling(_CrossingArray[index].Count); i++) {
StackPanel _StackPanel = new StackPanel();
_StackPanel.Orientation = Orientation.Horizontal;
_StackPanel.Margin = new Thickness(10, 10, 0, 10);
for (int j = 0; j < 2; j++) {
if (i * 2 + j >= _CrossingArray[index].Count) break;
StackPanel _InStackPanel = new StackPanel();
_InStackPanel.Orientation = Orientation.Vertical;
_InStackPanel.Margin = new Thickness(10, 10, 0, 10);
Button _Button = new Button();
_Button.Click += new RoutedEventHandler(Img_Click);
StackPanel _StackOnButton = new StackPanel();
BitmapImage imageBitmap = new BitmapImage(new Uri(_CrossingArray[index][i*2+j].ImagePath, UriKind.Absolute));
Image _Image = new Image();