Instantiate and use a WrapPanel element in code : WrapPanel « Windows Presentation Foundation « C# / CSharp Tutorial






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 ();
    }
  }








24.58.WrapPanel
24.58.1.Simple WrapPanelSimple WrapPanel
24.58.2.FlowDirection of WrapPanelFlowDirection of WrapPanel
24.58.3.WrapPanel with BackgroundWrapPanel with Background
24.58.4.Vertical WrapPanel WindowVertical WrapPanel Window
24.58.5.Set item width for WrapPanelSet item width for WrapPanel
24.58.6.Set ItemWidth and ItemHeight for WrapPanelSet ItemWidth and ItemHeight for WrapPanel
24.58.7.WrapPanel and Windows ControlsWrapPanel and Windows Controls
24.58.8.WrapPanel with VerticalAlignmentWrapPanel with VerticalAlignment
24.58.9.Instantiate and use a WrapPanel element in code