Export (0) Print
Expand All

Panel Class

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

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory::Ignore)] 
[ContentPropertyAttribute(L"Children")] 
public ref class Panel abstract : public FrameworkElement, IAddChild
/** @attribute LocalizabilityAttribute(LocalizationCategory.Ignore) */ 
/** @attribute ContentPropertyAttribute("Children") */ 
public abstract class Panel extends FrameworkElement implements IAddChild
LocalizabilityAttribute(LocalizationCategory.Ignore) 
ContentPropertyAttribute("Children") 
public abstract class Panel extends FrameworkElement implements IAddChild
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.

Content Model: Panel enforces a strong content model for child content. The Children collection of a Panel element can only consist of UIElement objects. 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.

This example shows how to override the default layout behavior of the Panel element and create custom layout elements that are derived from Panel.

The example defines a simple custom Panel element called PlotPanel, which positions child elements according to two hard-coded x- and y-coordinates. In this example, x and y are both set to 50; therefore, all child elements are positioned at that location on the x and y axes.

To implement custom Panel behaviors, the example uses the MeasureOverride and ArrangeOverride methods. Each method returns the Size data that is necessary to position and render child elements.

public: 
   ref class PlotPanel : Panel {

   public: 
      PlotPanel () {};

   protected: 
      // Override the default Measure method of Panel

      virtual Size MeasureOverride (Size availableSize) override 
      {
         Size childSize = availableSize;
         for each (UIElement^ child in InternalChildren)
         {
            child->Measure(childSize);
         }
         return availableSize;
      };

   protected: 
      virtual System::Windows::Size ArrangeOverride (Size finalSize) override 
      {
         for each (UIElement^ child in InternalChildren)
         {
            double x = 50;
            double y = 50;
            child->Arrange(Rect(Point(x, y), child->DesiredSize));
         }
         return finalSize;
      };
   };

For the complete sample, see Create a Simple Custom Panel Behavior Sample.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
            System.Windows.Controls.Panel
               Derived Classes

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft