Export (0) Print
Expand All

Panel.Background Property

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

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

public Brush Background { get; set; }
/** @property */
public Brush get_Background ()

/** @property */
public void set_Background (Brush value)

public function get Background () : Brush

public function set Background (value : Brush)

For XAML information, see the Brush type.

Property Value

A Brush. This default value is a null reference (Nothing in Visual Basic).

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.

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 class PlotPanel : Panel
{
    // Default public constructor
    public PlotPanel()
        : base()
    {
    }

    // Override the default Measure method of Panel
    protected override Size MeasureOverride(Size availableSize)
    {
        Size childSize = availableSize;
        foreach (UIElement child in InternalChildren)
        {
            child.Measure(childSize);
        }
        return availableSize;
    }
    protected override Size ArrangeOverride(Size finalSize)
    {
        foreach (UIElement child in InternalChildren)
        {
            double x = 50;
            double y = 50;

            child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
        }
        return finalSize; // Returns the final Arranged size
    }
}

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

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