#874 – Setting the Background for a Popup

You must explicitly set the Background for the controls hosted within a Popup control.  The Popup does not inherit the background brush of any parent element (e.g. a parent Window).

You typically set the Background property for the single element hosted within the Popup (e.g. a Border element).  If you don’t specify a value for the Background, the behavior depends on the value of the Popup’s AllowTransparency property:

  • If AllowTransparency is false, the background of the popup will be black
  • If AllowTransparency is true, the popup will be transparent

874-001

Below is an example where the Background is set for the Border element contained within the Popup.

        <Popup Name="popCaesar" StaysOpen="False"
               AllowsTransparency="True">
            <Border BorderBrush="Blue" BorderThickness="1"
                    Background="AliceBlue">
                <StackPanel Orientation="Horizontal">
                    <Image Source="Caesar.jpg" Height="100"/>
                    <TextBlock Text="Julius Caesar was a Roman emperor who lived from 100 BC to 44 BC"
                            Margin="10"
                            Width="150" TextWrapping="Wrap"/>
                </StackPanel>
            </Border>
        </Popup>

874-002

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #874 – Setting the Background for a Popup

  1. Pingback: Dew Drop – July 30, 2013 (#1,595) | Alvin Ashcraft's Morning Dew

Leave a comment