#874 – Setting the Background for a Popup
July 30, 2013 1 Comment
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
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>