Mega Code Archive

 
Categories / C# / WPF
 

Create a button when the page loads

<StackPanel   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   x:Class="WpfApplication1.FELoaded" Loaded="OnLoad" Name="root"> </StackPanel> //File:Window.xaml.cs using System; using System.Windows; using System.Windows.Controls; namespace WpfApplication1 {     public partial class FELoaded {         void OnLoad(object sender, RoutedEventArgs e)         {             Button b1 = new Button();             b1.Content = "New Button";             root.Children.Add(b1);             b1.Height = 25;             b1.Width = 200;             b1.HorizontalAlignment = HorizontalAlignment.Left;         }     } }