Add a button on the XAML page as follows:
View code
< Grid X: Name = "Layoutroot" Background = "White" >
< Button Width = "100" Height = "50" X: Name = "Showpopup" Click = "Showpopup_click"
Content = "Show popup" />
</ Grid >
AfterCodeAdd the following code to the page. XAML. CS file:
View code
Popup P = New Popup ();
Private Void Showpopup_click ( Object Sender, routedeventargs e ){
// Create a panel control that contains other controls
Stackpanel Panel1 = New Stackpanel ();
Panel1.background = New Solidcolorbrush (colors. Gray );
// Create a button
Button button1 = New Button ();
Button1.content = " Close " ;
Button1.margin = New Thickness ( 5.0 );
Button1.click + = New Routedeventhandler (button#click );
// Create text label
Textblock textblock1 = New Textblock ();
Textblock1.text = " The popup Control " ;
Textblock1.margin = New Thickness ( 5.0 );
// Add text label and button to panel
Panel1.children. Add (textblock1 );
Panel1.children. Add (button1 );
// Set Panel as the sub-panel of the pop-up layer. When panel is displayed, it is displayed as a pop-up layer.
P. Child = Panel1;
// Set location
P. verticaloffset = 25 ;
P. horizontaloffset = 25 ;
// Show the popup.
P. isopen = True ;
}
Void Button#click ( Object Sender, routedeventargs e ){
// Close the pop-up layer
P. isopen = False ;
}
Note: you must add a reference to the system. Windows. Controls. primitives naming control.
Run the applicationProgram. You can see a button on the page. When you click a button, a bullet with text labels and buttons
The output layer is displayed. When you click the button in the pop-up layer, the pop-up layer will be closed.