Popup class

Applies to Windows and Windows Phone

Displays content on top of existing content, within the bounds of the application window.

Inheritance

Object
  DependencyObject
    UIElement
      FrameworkElement
        Popup

Syntax


public sealed class Popup : FrameworkElement

Attributes

[ContentProperty("Name=Child")]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The Popup class has these types of members:

Constructors

The Popup class has these constructors.

ConstructorDescription
Popup

 

Events

The Popup class has these events.

EventDescription
Closed
DataContextChanged (Inherited from FrameworkElement)
DoubleTapped (Inherited from UIElement)
DragEnter (Inherited from UIElement)
DragLeave (Inherited from UIElement)
DragOver (Inherited from UIElement)
Drop (Inherited from UIElement)
GotFocus (Inherited from UIElement)
Holding (Inherited from UIElement)
KeyDown (Inherited from UIElement)
KeyUp (Inherited from UIElement)
LayoutUpdated (Inherited from FrameworkElement)
Loaded (Inherited from FrameworkElement)
LostFocus (Inherited from UIElement)
ManipulationCompleted (Inherited from UIElement)
ManipulationDelta (Inherited from UIElement)
ManipulationInertiaStarting (Inherited from UIElement)
ManipulationStarted (Inherited from UIElement)
ManipulationStarting (Inherited from UIElement)
Opened
PointerCanceled (Inherited from UIElement)
PointerCaptureLost (Inherited from UIElement)
PointerEntered (Inherited from UIElement)
PointerExited (Inherited from UIElement)
PointerMoved (Inherited from UIElement)
PointerPressed (Inherited from UIElement)
PointerReleased (Inherited from UIElement)
PointerWheelChanged (Inherited from UIElement)
RightTapped (Inherited from UIElement)
SizeChanged (Inherited from FrameworkElement)
Tapped (Inherited from UIElement)
Unloaded (Inherited from FrameworkElement)

 

Methods

The Popup class has these methods. It also inherits methods from the Object class.

MethodDescription
AddHandler (Inherited from UIElement)
Arrange (Inherited from UIElement)
ArrangeOverride (Inherited from FrameworkElement)
CancelDirectManipulations (Inherited from UIElement)
CapturePointer (Inherited from UIElement)
ClearValue (Inherited from DependencyObject)
FindName (Inherited from FrameworkElement)
FindSubElementsForTouchTargeting (Inherited from UIElement)
GetAnimationBaseValue (Inherited from DependencyObject)
GetBindingExpression (Inherited from FrameworkElement)
GetValue (Inherited from DependencyObject)
GoToElementStateCore (Inherited from FrameworkElement)
InvalidateArrange (Inherited from UIElement)
InvalidateMeasure (Inherited from UIElement)
Measure (Inherited from UIElement)
MeasureOverride (Inherited from FrameworkElement)
OnApplyTemplate (Inherited from FrameworkElement)
OnCreateAutomationPeer (Inherited from UIElement)
OnDisconnectVisualChildren (Inherited from UIElement)
ReadLocalValue (Inherited from DependencyObject)
ReleasePointerCapture (Inherited from UIElement)
ReleasePointerCaptures (Inherited from UIElement)
RemoveHandler (Inherited from UIElement)
SetBinding (Inherited from FrameworkElement)
SetValue (Inherited from DependencyObject)
TransformToVisual (Inherited from UIElement)
UpdateLayout (Inherited from UIElement)

 

Properties

The Popup class has these properties.

PropertyAccess typeDescription

ActualHeight

Read-only (Inherited from FrameworkElement)

ActualWidth

Read-only (Inherited from FrameworkElement)

AllowDrop

Read/write (Inherited from UIElement)

BaseUri

Read-only (Inherited from FrameworkElement)

CacheMode

Read/write (Inherited from UIElement)

Child

Read/write

ChildProperty

Read-only

ChildTransitions

Read/write

ChildTransitionsProperty

Read-only

Clip

Read/write (Inherited from UIElement)

CompositeMode

Read/write (Inherited from UIElement)

DataContext

Read/write (Inherited from FrameworkElement)

DesiredSize

Read-only (Inherited from UIElement)

Dispatcher

Read-only (Inherited from DependencyObject)

FlowDirection

Read/write (Inherited from FrameworkElement)

Height

Read/write (Inherited from FrameworkElement)

HorizontalAlignment

Read/write (Inherited from FrameworkElement)

HorizontalOffset

Read/write

HorizontalOffsetProperty

Read-only

IsDoubleTapEnabled

Read/write (Inherited from UIElement)

IsHitTestVisible

Read/write (Inherited from UIElement)

IsHoldingEnabled

Read/write (Inherited from UIElement)

IsLightDismissEnabled

Read/write

IsLightDismissEnabledProperty

Read-only

IsOpen

Read/write

IsOpenProperty

Read-only

IsRightTapEnabled

Read/write (Inherited from UIElement)

IsTapEnabled

Read/write (Inherited from UIElement)

Language

Read/write (Inherited from FrameworkElement)

ManipulationMode

Read/write (Inherited from UIElement)

Margin

Read/write (Inherited from FrameworkElement)

MaxHeight

Read/write (Inherited from FrameworkElement)

MaxWidth

Read/write (Inherited from FrameworkElement)

MinHeight

Read/write (Inherited from FrameworkElement)

MinWidth

Read/write (Inherited from FrameworkElement)

Name

Read/write (Inherited from FrameworkElement)

Opacity

Read/write (Inherited from UIElement)

Parent

Read-only (Inherited from FrameworkElement)

PointerCaptures

Read-only (Inherited from UIElement)

Projection

Read/write (Inherited from UIElement)

RenderSize

Read-only (Inherited from UIElement)

RenderTransform

Read/write (Inherited from UIElement)

RenderTransformOrigin

Read/write (Inherited from UIElement)

RequestedTheme

Read/write (Inherited from FrameworkElement)

Resources

Read/write (Inherited from FrameworkElement)

Style

Read/write (Inherited from FrameworkElement)

Tag

Read/write (Inherited from FrameworkElement)

Transitions

Read/write (Inherited from UIElement)

Triggers

Read-only (Inherited from FrameworkElement)

UseLayoutRounding

Read/write (Inherited from UIElement)

VerticalAlignment

Read/write (Inherited from FrameworkElement)

VerticalOffset

Read/write

VerticalOffsetProperty

Read-only

Visibility

Read/write (Inherited from UIElement)

Width

Read/write (Inherited from FrameworkElement)

 

Remarks

Do not use a Popup if a Flyout, MenuFlyout, ToolTip or MessageDialog is more appropriate.

Popup is a general purpose container for hosting UIElements on top of existing content. You typically use a Popup to temporarily display content that accomplishes a particular task. The Popup does not have a default visual template. Instead, you must set the content yourself by specifying a single Child element as content. You can define the Popup content inline, but it's common to define the content as a UserControl, and then set the UserControl as the Child of the Popup.

You position the Popup by setting the HorizontalOffset and VerticalOffset properties. The Popup is offset relative to its immediate parent container. A Popup is not modal, so input to the screen behind it is not blocked.

To show a Popup, set its IsOpen property to true. To hide the Popup, set IsOpen to false. You can set IsLightDismissEnabled to make the Popup hide automatically when a user taps anywhere away from it.

The Popup can host input controls. When hosting input controls like TextBox, the touch keyboard might slide into view when the user touches the input control. If the Popup's parent container is already in the visual tree, the Popup automatically repositions itself when the touch keyboard is in view. Otherwise, the Popup is not repositioned and the touch keyboard can cover it. This can happen if you create the Popup in code and set IsOpen to true without adding the Popup as a child of an element in the visual tree.

For more code examples that show the Popup control, see the XAML Popup sample.

Examples

This example shows a simple Popup with content defined inline.


<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
    <StackPanel>
        <Button Content="Show Popup (using Offset)" Click="ShowPopupOffsetClicked" />
    </StackPanel>
    <Popup VerticalOffset="10" HorizontalOffset="200" x:Name="StandardPopup">
        <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" 
                Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
                BorderThickness="2" Width="200" Height="200">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="Simple Popup" FontSize="24.667" HorizontalAlignment="Center" />
                <Button Content="Close" Click="ClosePopupClicked" HorizontalAlignment="Center" />
            </StackPanel>
        </Border>
    </Popup>
</Grid>


// Handles the Click event on the Button inside the Popup control and 
// closes the Popup. 
private void ClosePopupClicked(object sender, RoutedEventArgs e)
{
    // if the Popup is open, then close it 
    if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
}

// Handles the Click event on the Button on the page and opens the Popup. 
private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
{
    // open the Popup if it isn't open already 
    if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
} 

This example shows a Popup that has a UserControl set as its Child element. The UserControl defines the content of the Popup.


<Popup x:Name="ParentedPopup" HorizontalOffset="200" VerticalOffset="200">
    <local:PopupInputContent />
</Popup>


<UserControl
    x:Class="XAMLPopup.PopupInputContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PopupExample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">
    <Grid>
        <StackPanel>
            <TextBlock Text="Type some input" FontSize="24.667" />
            <TextBox Width="300" Height="55" />
            <Button Content="Save" Click="SimulateSaveClicked" />
        </StackPanel>
    </Grid>
</UserControl>


using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;

namespace XAMLPopup
{
    public sealed partial class PopupInputContent : UserControl
    {
        public PopupInputContent()
        {
            this.InitializeComponent();
        }

        // Handles the Click event of the 'Save' button simulating a save and close 
        private void SimulateSaveClicked(object sender, RoutedEventArgs e)
        {
            // in this example we assume the parent of the UserControl is a Popup 
            Popup p = this.Parent as Popup;

            // close the Popup
            if (p != null) { p.IsOpen = false; }  
        } 
    }
}

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls.Primitives
Windows::UI::Xaml::Controls::Primitives [C++]

Metadata

Windows.winmd

See also

FrameworkElement

 

 

Show:
© 2014 Microsoft