merge main branch

This commit is contained in:
CXWTool Service Account
2021-07-20 05:00:55 +00:00
32 changed files with 941 additions and 145 deletions
@@ -1,7 +1,7 @@
---
title: "Popup Overview"
description: Learn about the Windows Presentation Foundation Popup control, which provides a way to display content in a window that floats over the current application.
ms.date: "03/30/2017"
ms.date: "07/14/2021"
helpviewer_keywords:
- "controls [WPF], Popup"
- "Popup control [WPF], about Popup control"
@@ -19,12 +19,11 @@ The <xref:System.Windows.Controls.Primitives.Popup> control provides a way to di
<a name="APopupExample"></a>
## Creating a Popup
The following example shows how to define a <xref:System.Windows.Controls.Primitives.Popup> control that is the child element of a <xref:System.Windows.Controls.Button> control. Because a <xref:System.Windows.Controls.Button> can have only one child element, this example places the text for the <xref:System.Windows.Controls.Button> and the <xref:System.Windows.Controls.Primitives.Popup> controls in a <xref:System.Windows.Controls.StackPanel>. The content of the <xref:System.Windows.Controls.Primitives.Popup> appears in a <xref:System.Windows.Controls.TextBlock> control, which displays its text in a separate window that floats over the application window near the related <xref:System.Windows.Controls.Button> control.
[!code-xaml[PopupSimple#1](~/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/Window1.xaml#1)]
[!code-xaml[PopupSimple#CreatePopupCodeXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/Window1.xaml#createpopupcodexaml)]
The following example shows how to define a <xref:System.Windows.Controls.Primitives.Popup> control that is the child element of a <xref:System.Windows.Controls.Primitives.ToggleButton> control. Because a `ToggleButton` can have only one child element, this example places the text for the `ToggleButton` and the `Popup` controls in a <xref:System.Windows.Controls.StackPanel>. The content of the `Popup` is displayed in a separate window that floats over the application window near the related `ToggleButton` control.
:::code language="xaml" source="snippets/popup-overview/csharp/Window1.xaml" id="ToggleButtonCodeless":::
<a name="PopupUses"></a>
## Controls That Implement a Popup
You can build <xref:System.Windows.Controls.Primitives.Popup> controls into other controls. The following controls implement the <xref:System.Windows.Controls.Primitives.Popup> control for specific uses:
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWpf>true</UseWpf>
</PropertyGroup>
</Project>
@@ -0,0 +1,64 @@
<Window x:Class="Popup_Properties_Sample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Popup_Properties_Sample"
>
<StackPanel>
<Border HorizontalAlignment="Left" BorderThickness="2" Margin="10,10,0,0"
BorderBrush="Green" Background="Beige" Width="300">
<TextBlock Foreground="Blue" FontSize="12" Margin="10,10,10,10"
TextWrapping="Wrap" >
This sample shows examples of a Popup controls
that are the logical children of a Buttons. Each Popup
window is positioned with respect to a Button. However,
because the Popup content is contained in its own window,
the Popup is not a visual child of the Button.
</TextBlock>
</Border>
<TextBlock/>
<TextBlock Foreground="Blue" FontSize="12" Margin="20,10,10,10"
TextWrapping="Wrap" Width="300" HorizontalAlignment="Left">
Type the content you want to appear in the Popup in the text
box below and then click the button to display the Popup
</TextBlock>
<TextBox Name="myTextBox" Margin="20,0,0,0" Foreground="HotPink"
Width="150" HorizontalAlignment="Left" TextChanged="setColors">
Type your Popup text here
</TextBox>
<!--<ToggleButtonCodeless>-->
<ToggleButton x:Name="TogglePopupButton" Height="30" Width="150" HorizontalAlignment="Left">
<StackPanel>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">
<Run Text="Is button toggled? " />
<Run Text="{Binding IsChecked, ElementName=TogglePopupButton}" />
</TextBlock>
<Popup Name="myPopup" IsOpen="{Binding IsChecked, ElementName=TogglePopupButton}">
<Border BorderThickness="1">
<TextBlock Name="myPopupText" Background="LightBlue" Foreground="Blue" Padding="30">
Popup Text
</TextBlock>
</Border>
</Popup>
</StackPanel>
</ToggleButton>
<!--</ToggleButtonCodeless>-->
<TextBlock Foreground="Blue" FontSize="12" Margin="10,40,10,0"
TextWrapping="Wrap">
Click the button to create a Popup by using code
</TextBlock>
<!--<SnippetCreatePopupCodeXAML>-->
<Button HorizontalAlignment="Left" Click="CreatePopup"
Width="150" Margin="20,10,0,0">
<StackPanel Name="ButtonContentContainer">
<TextBlock>Create Popup</TextBlock>
</StackPanel>
</Button>
<!--</SnippetCreatePopupCodeXAML>-->
</StackPanel>
</Window>
@@ -0,0 +1,55 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Popup_Properties_Sample
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
// Sample event handler:
private void DisplayPopup(object sender, RoutedEventArgs e)
{
myPopupText.Text = myTextBox.Text;
myPopup.IsOpen = true;
myPopup.StaysOpen = false;
}
// Used in UIElement.IsFocused.
//<SnippetIsFocused>
private void setColors(object sender, RoutedEventArgs e)
{
if (myTextBox.IsFocused) myTextBox.Foreground = Brushes.Brown;
}
//</SnippetIsFocused>
//<CreatePopup>
private void CreatePopup(object sender, RoutedEventArgs e)
{
Popup codePopup = new Popup();
TextBlock popupText = new()
{
Text = "Popup Text",
Background = Brushes.LightBlue,
Foreground = Brushes.Blue
};
codePopup.Child = popupText;
ButtonContentContainer.Children.Add(codePopup);
codePopup.IsOpen = true;
}
//</CreatePopup>
}
}
@@ -0,0 +1,9 @@
<Application x:Class="Popup_Properties_Sample.app"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="AppStartup"
>
<Application.Resources>
</Application.Resources>
</Application>
@@ -0,0 +1,22 @@
using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;
namespace Popup_Properties_Sample
{
/// <summary>
/// Interaction logic for app.xaml
/// </summary>
public partial class app : Application
{
void AppStartup(object sender, StartupEventArgs args)
{
Window1 mainWindow = new Window1();
mainWindow.Show();
}
}
}