Introduction to WPF Popups

The popup control is a new primitive control in the WPF framework.  It allows a container control within the popup to suddenly appear when some action is taken (such as a button click).  For instance, below is an instance of a popup:

<Popup x:Name="ConnectPopup" Grid.Row="0" PopupAnimation="Fade" PlacementTarget="{Binding ElementName=TabLayout}" Placement="Bottom" PlacementRectangle="20,25,40,30">
  <Grid />
</Popup>

Within the popup control can be a container control, such as a grid, with whatever content within that grid control it so chooses.  The popup can also control the animation used to show/hide itself.  To show/hide a popup, use the following code:

this.ConnectPopup.IsOpen = true;
this.ConnectPopup.StaysOpen = false;

IsOpen determines whether a popup is displayed, and by setting this value to true it displays it.  StaysOpen determines whether it can be closed by some means.

Notice one other thing in the markup above.  Placement determines the overall placement of the popup, and Bottom means at the bottom of the control that is in reference via the PlacementTarget.  So what it is saying is place it in relativity to the TabLayout control, which is the placement target.  See this for more information about how all of this works with a placement rectangle:  http://msdn2.microsoft.com/en-us/library/system.windows.controls.primitives.popup.placementtarget.aspx

Published Thursday, July 26, 2007 7:26 PM by bmains
Filed under:

Comments

No Comments