Panel.Background Property

Definition

Gets or sets a Brush that fills the panel content area.

C#
public Brush Background { get; set; }
XAML
<panel Background="{StaticResource resourceName}"/>
- or -
<panel Background="colorString"/>
- or -
<panel>
  <panel.Background>singleBrush</panel.Background>
</panel>

Property Value

The brush that fills the panel content area. The default is null, (a null brush) which is evaluated as Transparent for rendering.

Remarks

The Background value for a Panel-derived panel is visible underneath the inner area if the elements that are in the Children collection have transparency or null brushes for any of their defining area. It displays in the child margin area for any case where a child element has a nonzero Margin affecting its position. It is also visible between the layout positions of any child elements regardless of margin, although that can depend on how the panel implements its layout behavior. For example, in a Canvas, any pixel in the content area where there's not an absolutely positioned element covering it will show the panel Background brush.

If you're using a Panel class such as Grid or StackPanel as the root element of a control template, it's a common practice to use a {TemplateBinding} markup extension to bind the panel's background to the Control.Background property of the template parent (the control class that uses your template).

Applies to

Product Versions
WinRT Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100

See also