Mega Code Archive

 
Categories / C# Tutorial / WPF
 

Instantiate and use a WrapPanel element in code

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Threading;   public class app : System.Windows.Application   {         System.Windows.Controls.Button btn1;         System.Windows.Controls.Button btn2;         System.Windows.Controls.Button btn3;         System.Windows.Controls.WrapPanel myWrapPanel = new WrapPanel();     System.Windows.Window mainWindow = new System.Windows.Window();     protected override void OnStartup (StartupEventArgs e)     {       base.OnStartup (e);             mainWindow.Title = "WrapPanel Sample";                    myWrapPanel.Background = System.Windows.Media.Brushes.Azure;             myWrapPanel.Orientation = Orientation.Horizontal;             myWrapPanel.ItemHeight = 25;             myWrapPanel.ItemWidth = 75;             myWrapPanel.Width = 150;             myWrapPanel.HorizontalAlignment = HorizontalAlignment.Left;             myWrapPanel.VerticalAlignment = VerticalAlignment.Top;             btn1 = new Button();             btn1.Content = "Button 1";             btn2 = new Button();             btn2.Content = "Button 2";             btn3 = new Button();             btn3.Content = "Button 3";             myWrapPanel.Children.Add(btn1);             myWrapPanel.Children.Add(btn2);             myWrapPanel.Children.Add(btn3);             mainWindow.Content = myWrapPanel;       mainWindow.Show();     }     [System.STAThread()]     private static void Main ()     {       app app = new app ();       app.Run ();     }   }