Panel Content Model Overview

This content model overview describes the supported content for a Panel. StackPanel and DockPanel are examples of Panel objects.

This topic contains the following sections.

A Panel has the following content properties.

The Children property can contain multiple objects, even other Panel objects. The following example shows how to use the Children property to add two Button objects to a StackPanel.

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    <Button>Button 1</Button>
    <Button>Button 2</Button>
  </StackPanel>
</Page>
using System;
using System.Windows;
using System.Windows.Controls;

namespace SDKSample
{
    public partial class StackpanelExample : Page
    {
        public StackpanelExample()
        {
            // Create two buttons
            Button myButton1 = new Button();
            myButton1.Content = "Button 1";
            Button myButton2 = new Button();
            myButton2.Content = "Button 2";

            // Create a StackPanel
            StackPanel myStackPanel = new StackPanel();

            // Add the buttons to the StackPanel
            myStackPanel.Children.Add(myButton1);
            myStackPanel.Children.Add(myButton2);

            this.Content = myStackPanel;
        }
    }
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft