共用方式為


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.

  • Panel Content Property
  • Using the Children Property
  • Types That Share This Content Model
  • Types That Can Contain Panel Objects
  • Related Topics

Panel Content Property

A Panel has the following content properties.

Using the Children Property

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="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://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;
        }
    }
}

Types That Share This Content Model

The following classes inherit from the Panel class.

Types That Can Contain Panel Objects

You can use the Panel class as content for the following types:

See Also

Concepts

Panels Overview
Panel Types

Other Resources

Content Models
Type Families