WPF Popup
A popup in WPF is a window that floats over a page or window providing the functionality for some quick action, for example, a login control on a page or window or an animated popup tip of a control.
Introduction to WPF Popup
The Popup element of XAML represents a WPF Popup control.
- <Popup></Popup>
The Width and the Height properties represent the width and the height of a popup. The Name property represents the name of the control that is a unique identifier of a control. The Margin property is used to set the location of a Popup on the parent control. The HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.
The following code snippet sets the name, height, and width of a Popup control. The code also sets horizontal alignment to left and vertical alignment to top.
- <Popup Margin="10,10,0,13" Name="Popup1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="194" Height="200" />
To make a popup control visible, you need to set IsOpen property to true.
IsOpen="True"
Adding WPF Popup Contents
A Popup control can have only one child. The following code snippet adds a text block to the popup control.
- <Popup Margin="10,10,0,13" Name="Popup1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="194" Height="200" IsOpen="True">
- <TextBlock Name="McTextBlock" Background="LightBlue"> This is popup text </TextBlock>
- </Popup>
If you wish to add more contents to the popup control, you may have a stack panel or grid as a child control and place more contents on the panel or grid controls. The following code snippet creates a stack panel and places some contents on it.
- <Popup Margin="10,10,0,13" Name="Popup1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="194" Height="200" IsOpen="True">
- <StackPanel>
- <TextBlock Name="McTextBlock" Background="LightBlue"> This is popup text </TextBlock>
- <Button Content="This is button on a Pupup" />
- </StackPanel>
- </Popup>


Join the conversation! Your thoughts help the community grow.