using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
class MainClass : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new MainClass());
}
public MainClass()
{
SizeToContent = SizeToContent.WidthAndHeight;
ResizeMode = ResizeMode.CanMinimize;
AddHandler(Button.ClickEvent, new RoutedEventHandler(ButtonOnClick));
StackPanel stackMain = new StackPanel();
stackMain.Orientation = Orientation.Horizontal;
stackMain.Margin = new Thickness(5);
Content = stackMain;
for (int i = 0; i < 2; i++)
{
StackPanel stackChild = new StackPanel();
stackMain.Children.Add(stackChild);
for (int j = 0; j < 3; j++)
{
Button btn = new Button();
btn.Content = "Button";
btn.Margin = new Thickness(10);
stackChild.Children.Add(btn);
}
}
}
void ButtonOnClick(object sender, RoutedEventArgs args)
{
Console.WriteLine((args.Source as Button).Content);
}
}
|