Popup in WPF using VB.NET
In this article you will learn how to work with Popup control in WPF.
Popup: 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.
Like the ToolTip, the Popup can hold a single piece of content, which can include any WPF element. Also, like the ToolTip, the content in the Popup can extend beyond the bounds of the window. 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 must be shown manually, you may choose to create it entirely in code. However, you can define it just as easily in XAML markupâ€"just make sure to include the name property so you can manipulate it in code.
Example of an Popup control
XMAL Code
<Window x:Class="WpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="150" Width="250">
<StackPanel>
<Popup AllowsTransparency="True" Height="150" HorizontalOffset="1cm" Name="myPopup"
Placement="Right" StaysOpen="True" Width="250" >
<Border BorderBrush="Black" BorderThickness="3">
<DockPanel Background="White" LastChildFill="True">
<TextBlock Background="LightBlue" DockPanel.Dock="Top"
FontSize="15" HorizontalAlignment="Stretch"
Margin="6" Text="Popup" />
<Button Click="btnClosePopup_Click" Content="Close"
DockPanel.Dock="Bottom" Margin="6"
HorizontalAlignment="Right" MaxHeight="24"/>
</DockPanel>
</Border>
</Popup>
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="2" />
<EventSetter Event="Click" Handler="btnShowPopup_Click" />
</Style>
</StackPanel.Resources>
<Button Content="Show Popup" Name="btnShowPopup" />
</StackPanel>
</StackPanel>
</Window>
VB.NET Code
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Controls.Primitives
Namespace WpfApplication
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub btnClosePopup_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
myPopup.IsOpen = False
End Sub
Private Sub btnShowPopup_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
myPopup.IsOpen = True
End Sub
End Class
End Namespace
Output window
Conclusion
Hope this article help you to understand the working of Popup control in WPF.