mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: "Popup Overview"
|
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.
|
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:
|
helpviewer_keywords:
|
||||||
- "controls [WPF], Popup"
|
- "controls [WPF], Popup"
|
||||||
- "Popup control [WPF], about Popup control"
|
- "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>
|
<a name="APopupExample"></a>
|
||||||
## Creating a Popup
|
## 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.
|
|
||||||
|
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-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)]
|
|
||||||
|
|
||||||
|
:::code language="xaml" source="snippets/popup-overview/csharp/Window1.xaml" id="ToggleButtonCodeless":::
|
||||||
|
|
||||||
<a name="PopupUses"></a>
|
<a name="PopupUses"></a>
|
||||||
## Controls That Implement a Popup
|
## 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:
|
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:
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net5.0-windows</TargetFramework>
|
||||||
|
<UseWpf>true</UseWpf>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
||||||
+64
@@ -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>
|
||||||
+10
-10
@@ -36,20 +36,20 @@ namespace Popup_Properties_Sample
|
|||||||
}
|
}
|
||||||
//</SnippetIsFocused>
|
//</SnippetIsFocused>
|
||||||
|
|
||||||
//<SnippetCreatePopupCode>
|
//<CreatePopup>
|
||||||
private void CreatePopup(object sender, RoutedEventArgs e)
|
private void CreatePopup(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
//<SnippetCreatePopup>
|
|
||||||
Popup codePopup = new Popup();
|
Popup codePopup = new Popup();
|
||||||
TextBlock popupText = new TextBlock();
|
TextBlock popupText = new()
|
||||||
popupText.Text = "Popup Text";
|
{
|
||||||
popupText.Background = Brushes.LightBlue;
|
Text = "Popup Text",
|
||||||
popupText.Foreground = Brushes.Blue;
|
Background = Brushes.LightBlue,
|
||||||
|
Foreground = Brushes.Blue
|
||||||
|
};
|
||||||
codePopup.Child = popupText;
|
codePopup.Child = popupText;
|
||||||
//</SnippetCreatePopup>
|
ButtonContentContainer.Children.Add(codePopup);
|
||||||
aStackPanel.Children.Add(codePopup);
|
|
||||||
codePopup.IsOpen = true;
|
codePopup.IsOpen = true;
|
||||||
}
|
}
|
||||||
//</SnippetCreatePopupCode>
|
//</CreatePopup>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{D3D69C55-A09F-473C-99B8-876826A68796}</ProjectGuid>
|
|
||||||
<RootNamespace>Popup_Properties_Sample</RootNamespace>
|
|
||||||
<AssemblyName>Popup Properties Sample</AssemblyName>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<OutputType>winexe</OutputType>
|
|
||||||
<ApplicationVersion>1.0.0.*</ApplicationVersion>
|
|
||||||
<!-- Most people will use Publish dialog in Visual Studio to increment this -->
|
|
||||||
<ProductVersion>10.0.20821</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
|
||||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>.\bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugSymbols>false</DebugSymbols>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>.\bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
<Reference Include="WindowsBase" />
|
|
||||||
<Reference Include="PresentationCore" />
|
|
||||||
<Reference Include="PresentationFramework" />
|
|
||||||
<Reference Include="System.Xaml">
|
|
||||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="UIAutomationProvider" />
|
|
||||||
<Reference Include="UIAutomationTypes" />
|
|
||||||
<Reference Include="System.ServiceModel" />
|
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ApplicationDefinition Include="app.xaml" />
|
|
||||||
<Page Include="Window1.xaml" />
|
|
||||||
<Compile Include="app.xaml.cs">
|
|
||||||
<DependentUpon>app.xaml</DependentUpon>
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Window1.xaml.cs">
|
|
||||||
<DependentUpon>Window1.xaml</DependentUpon>
|
|
||||||
<SubType>Code</SubType>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
|
||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
<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>
|
|
||||||
<!--<Snippet1>-->
|
|
||||||
<Button HorizontalAlignment="Left" Click="DisplayPopup"
|
|
||||||
Width="150" Margin="20,10,0,0">
|
|
||||||
<StackPanel>
|
|
||||||
<TextBlock>Display Your Popup Text</TextBlock>
|
|
||||||
<!--<Snippet2>-->
|
|
||||||
<Popup Name="myPopup">
|
|
||||||
<TextBlock Name="myPopupText"
|
|
||||||
Background="LightBlue"
|
|
||||||
Foreground="Blue">
|
|
||||||
Popup Text
|
|
||||||
</TextBlock>
|
|
||||||
</Popup>
|
|
||||||
<!--</Snippet2>-->
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<!--</Snippet1>-->
|
|
||||||
|
|
||||||
<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 Name="ButtonForPopup" HorizontalAlignment="Left"
|
|
||||||
Click="CreatePopup"
|
|
||||||
Width="150" Margin="20,10,0,0">
|
|
||||||
<StackPanel Name="aStackPanel">
|
|
||||||
<TextBlock>Create Popup</TextBlock>
|
|
||||||
</StackPanel>
|
|
||||||
</Button>
|
|
||||||
<!--</SnippetCreatePopupCodeXAML>-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</StackPanel>
|
|
||||||
</Window>
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
wcsamp_components_popupsimple
|
|
||||||
Reference in New Issue
Block a user