Share via


面板內容模型概觀

更新:2007 年 11 月

本內容模型概觀說明 Panel 支援的內容。StackPanelDockPanelPanel 物件的範例。

這個主題包含下列章節。

  • 面板內容屬性
  • 使用 Children 屬性
  • 共用這個內容模型的型別
  • 可以包含 Panel 物件的型別
  • 相關主題

面板內容屬性

Panel 具有下列內容屬性。

使用 Children 屬性

Children 屬性可以包含多個物件,即使是其他 Panel 物件。下列範例顯示如何使用 Children 屬性將兩個 Button 物件加入至 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;
        }
    }
}

共用這個內容模型的型別

下列類別繼承自 Panel 類別。

可以包含 Panel 物件的型別

請參閱 WPF 內容模型

請參閱

概念

面板概觀