Panel Class

Definition

Provides a base class for all Panel elements. Use Panel elements to position and arrange child objects in Windows Presentation Foundation (WPF) applications.

[System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)]
[System.Windows.Markup.ContentProperty("Children")]
public abstract class Panel : System.Windows.FrameworkElement, System.Windows.Markup.IAddChild
Inheritance
Derived
Attributes
Implements

Inherited Members

System.Object

System.Windows.DependencyObject

System.Windows.FrameworkElement

System.Windows.Media.Visual

System.Windows.Threading.DispatcherObject

System.Windows.UIElement

Examples

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

Imports System
Imports System.Windows
Imports System.Windows.Controls

Namespace SDKSample
	Partial Public Class StackpanelExample
		Inherits Page
		Public Sub New()
			' Create two buttons
			Dim myButton1 As New Button()
			myButton1.Content = "Button 1"
			Dim myButton2 As New Button()
			myButton2.Content = "Button 2"

			' Create a StackPanel
			Dim myStackPanel As New StackPanel()

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

			Me.Content = myStackPanel
		End Sub
	End Class
End Namespace

Remarks

A Panel contains a collection of UIElement objects, which are in the Children property. Adding a UIElement child to a Panel implicitly adds it to the UIElementCollection for the Panel element.

WPF provides a comprehensive suite of derived Panel implementations, enabling many complex layouts. If you want to implement new layout containers, use the MeasureOverride and ArrangeOverride methods. For a demonstration of how to use these methods, see Create a Custom Content-Wrapping Panel Sample.

Panel elements do not receive mouse or stylus events if a Background is not defined. If you need to handle mouse or stylus events but do not want a background for your Panel, use Transparent.

Panel elements do not receive focus by default. To compel a panel element to receive focus, set the Focusable property to true.

Constructors

Panel()

Initializes a new instance of the Panel class.

Fields

Background​Property

Identifies the Background dependency property.

Is​Items​Host​Property

Identifies the IsItemsHost dependency property.

Z​Index​Property

Identifies the System.Windows.Controls.Panel.ZIndex attached property.

Properties

Background

Gets or sets a Brush that is used to fill the area between the borders of a Panel.

Children

Gets a UIElementCollection of child elements of this Panel.

Has​Logical​Orientation

Gets a value that indicates whether this Panel arranges its descendants in a single dimension.

Has​Logical​Orientation​Public

Gets a value that indicates whether this Panel arranges its descendants in a single dimension.

Internal​Children

Gets a UIElementCollection of child elements.

Is​Items​Host

Gets or sets a value that indicates that this Panel is a container for user interface (UI) items that are generated by an ItemsControl.

Logical​Children

Gets an enumerator that can iterate the logical child elements of this Panel element.

Logical​Orientation

The Orientation of the panel, if the panel supports layout in only a single dimension.

Logical​Orientation​Public

The Orientation of the panel, if the panel supports layout in only a single dimension.

Visual​Children​Count

Gets the number of child Visual objects in this instance of Panel.

Methods

Create​UI​Element​Collection(​Framework​Element)

Creates a new UIElementCollection.

Get​Visual​Child(​Int32)

Gets a Visual child of this Panel at the specified index position.

Get​ZIndex(​UI​Element)

Gets the value of the System.Windows.Controls.Panel.ZIndex property for a given element.

On​Is​Items​Host​Changed(​Boolean, ​Boolean)

Indicates that the IsItemsHost property value has changed.

On​Render(​Drawing​Context)

Draws the content of a DrawingContext object during the render pass of a Panel element.

On​Visual​Children​Changed(​Dependency​Object, ​Dependency​Object)

Invoked when the VisualCollection of a visual object is modified.

Set​ZIndex(​UI​Element, ​Int32)

Sets the value of the System.Windows.Controls.Panel.ZIndex attached property for a given element.

Should​Serialize​Children()

Determines whether the Children collection of a panel should be serialized.

Explicit Interface Implementations

I​Add​Child.​Add​Child(​Object)

This type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

I​Add​Child.​Add​Text(​String)

This type or member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.