using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfControl3 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { Label L1 = new Label(); Label L2 = new Label(); public MainWindow() { InitializeComponent(); StackPanel sp = new StackPanel(); //add the StackPanel as sole child of Window this.Content = sp; sp.Margin = new Thickness(10,10,10, 10); sp.Background = new SolidColorBrush(Colors.White); sp.Orientation = Orientation.Vertical; //Label sp.Children.Add(L1); sp.Children.Add(L2); //Button1 Button btn1 = new Button(); btn1.Content = "Im Top of Stack"; btn1.Width = 200; sp.Children.Add(btn1); btn1.Click += new RoutedEventHandler(Click_Me); //Button2 Button btn2 = new Button(); btn2.Content = "Im Bottom of Stack"; btn2.Width = 160; sp.Children.Add(btn2); btn2.Click += new RoutedEventHandler(Click_Me); } public void Click_Me(object sender, RoutedEventArgs e) { // MessageBox.Show("Hello Wrold" + e.Source.ToString()); L1.Content = ""; L2.Content = ""; L1.Content = sender.ToString(); L2.Content = e.Source.ToString(); // won't show up LC1.Content = "new code"; } } }