Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Popup Class

Represents a control that creates a separate pop-up window that has content.

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

[ContentPropertyAttribute("Child")] 
[LocalizabilityAttribute(LocalizationCategory.None)] 
public class Popup : FrameworkElement, IAddChild
/** @attribute ContentPropertyAttribute("Child") */ 
/** @attribute LocalizabilityAttribute(LocalizationCategory.None) */ 
public class Popup extends FrameworkElement implements IAddChild
ContentPropertyAttribute("Child") 
LocalizabilityAttribute(LocalizationCategory.None) 
public class Popup extends FrameworkElement implements IAddChild
<Popup>
  Child
</Popup>

Content Model: Popup has one content property: Child. A Popup can have a maximum of one child, which can be any UIElement.

To add a Child object to a Popup in Extensible Application Markup Language (XAML), nest the object in the Popup element tags. The following example shows how to create a Popup control by using Extensible Application Markup Language (XAML).

<Popup Name="myPopup">
  <TextBlock Name="myPopupText" 
             Background="LightBlue" 
             Foreground="Blue">
    Popup Text
  </TextBlock>
</Popup>

To add content to a Popup in code, use the Child object. The following example shows how to create a Popup control by using code.

Popup codePopup = new Popup();
TextBlock popupText = new TextBlock();
popupText.Text = "Popup Text";
popupText.Background = Brushes.LightBlue;
popupText.Foreground = Brushes.Blue;
codePopup.Child = popupText;

The following illustration shows a Popup control that has a Button as its parent.

Popup illustration

A Popup displays its content in its own window on the screen. When Popup is displayed on the screen, it does not reposition itself if its parent is repositioned.

A Popup control supports animation when the AllowsTransparency property is set to true and the application is running with full trust. An application that is running with full trust has complete access to system resources and is typically installed on the user's system. For more information, see Security.

The Parent property must be set on the Popup when used in a XAML browser application (XBAP).

For bitmap and opacity effects to appear on the content of a Popup, you must set the effects directly on the Popup content. The content of a Popup does not inherit effects that are set on the Popup control or on any other element that is in the parent window.

A Popup is sized to its content by default. When this occurs, applying a RenderTransform or bitmap effects may cause the Popup to be obscured. This occurs because the default size of the content does not provide enough area for the effects to display. If more space is required, you can define a margin around the Popup content to increase the area that is available to the control. For an example, see Animated Popup Sample.

To create a tooltip, use the ToolTip and ToolTipService classes. For more information, see ToolTip Overview.

This example shows how to create a Popup control. Use Popup controls to display brief information or menus in a separate window that floats above your application window relative to a designated element or screen coordinate.

The following example shows how to create a Popup that is the logical child of a Button control. A Button can have only one child; hence, the text for the Button and Popup controls is embedded in a StackPanel. The Popup content contains a TextBlock that displays content that is typed in a TextBox by the user in the Popup window when it is visible.

<Button HorizontalAlignment="Left" Click="DisplayPopup" 
        Width="150" Margin="20,10,0,0">
  <StackPanel>
    <TextBlock>Display Your Popup Text</TextBlock>
    <Popup Name="myPopup">
      <TextBlock Name="myPopupText" 
                 Background="LightBlue" 
                 Foreground="Blue">
        Popup Text
      </TextBlock>
    </Popup>
  </StackPanel>
</Button>

For the complete sample, see Popup Sample.

More Code

How to: Position a Popup

This set of examples shows how to use the placement properties to specify the position of a Popup control.

How to: Animate a Popup

This example shows two ways to animate a Popup control.

How to: Specify a Custom Popup Position

This example shows how to specify a custom position for a Popup control when the Placement property is set to Custom.

How to: Set the Placement Property for a Popup or Tooltip

This example shows how the PlacementMode enumeration values help you position a Popup or a tooltip control. Use the PlacementMode enumeration values to set the Popup.Placement, ToolTip.Placement, and ToolTipService.Placement properties.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
            System.Windows.Controls.Primitives.Popup

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

Show:
© 2014 Microsoft