Skip to content

Commit b0376d8

Browse files
authored
Update popup code (#1111)
* Update popup code * update xref
1 parent 5d38c60 commit b0376d8

File tree

9 files changed

+89
-139
lines changed

9 files changed

+89
-139
lines changed

dotnet-desktop-guide/framework/wpf/controls/popup-overview.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Popup Overview"
33
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.
4-
ms.date: "03/30/2017"
4+
ms.date: "07/14/2021"
55
helpviewer_keywords:
66
- "controls [WPF], Popup"
77
- "Popup control [WPF], about Popup control"
@@ -19,12 +19,11 @@ The <xref:System.Windows.Controls.Primitives.Popup> control provides a way to di
1919
2020
<a name="APopupExample"></a>
2121
## Creating a Popup
22-
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.
23-
24-
[!code-xaml[PopupSimple#1](~/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/Window1.xaml#1)]
25-
26-
[!code-xaml[PopupSimple#CreatePopupCodeXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/Window1.xaml#createpopupcodexaml)]
22+
23+
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.
2724

25+
:::code language="xaml" source="snippets/popup-overview/csharp/Window1.xaml" id="ToggleButtonCodeless":::
26+
2827
<a name="PopupUses"></a>
2928
## Controls That Implement a Popup
3029
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:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net5.0-windows</TargetFramework>
6+
<UseWpf>true</UseWpf>
7+
</PropertyGroup>
8+
9+
</Project>
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<Window x:Class="Popup_Properties_Sample.Window1"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="Popup_Properties_Sample"
5+
>
6+
<StackPanel>
7+
<Border HorizontalAlignment="Left" BorderThickness="2" Margin="10,10,0,0"
8+
BorderBrush="Green" Background="Beige" Width="300">
9+
<TextBlock Foreground="Blue" FontSize="12" Margin="10,10,10,10"
10+
TextWrapping="Wrap" >
11+
This sample shows examples of a Popup controls
12+
that are the logical children of a Buttons. Each Popup
13+
window is positioned with respect to a Button. However,
14+
because the Popup content is contained in its own window,
15+
the Popup is not a visual child of the Button.
16+
</TextBlock>
17+
</Border>
18+
<TextBlock/>
19+
<TextBlock Foreground="Blue" FontSize="12" Margin="20,10,10,10"
20+
TextWrapping="Wrap" Width="300" HorizontalAlignment="Left">
21+
Type the content you want to appear in the Popup in the text
22+
box below and then click the button to display the Popup
23+
</TextBlock>
24+
<TextBox Name="myTextBox" Margin="20,0,0,0" Foreground="HotPink"
25+
Width="150" HorizontalAlignment="Left" TextChanged="setColors">
26+
Type your Popup text here
27+
</TextBox>
28+
<!--<ToggleButtonCodeless>-->
29+
<ToggleButton x:Name="TogglePopupButton" Height="30" Width="150" HorizontalAlignment="Left">
30+
<StackPanel>
31+
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">
32+
<Run Text="Is button toggled? " />
33+
<Run Text="{Binding IsChecked, ElementName=TogglePopupButton}" />
34+
</TextBlock>
35+
36+
<Popup Name="myPopup" IsOpen="{Binding IsChecked, ElementName=TogglePopupButton}">
37+
<Border BorderThickness="1">
38+
<TextBlock Name="myPopupText" Background="LightBlue" Foreground="Blue" Padding="30">
39+
Popup Text
40+
</TextBlock>
41+
</Border>
42+
</Popup>
43+
</StackPanel>
44+
</ToggleButton>
45+
<!--</ToggleButtonCodeless>-->
46+
47+
<TextBlock Foreground="Blue" FontSize="12" Margin="10,40,10,0"
48+
TextWrapping="Wrap">
49+
Click the button to create a Popup by using code
50+
</TextBlock>
51+
<!--<SnippetCreatePopupCodeXAML>-->
52+
<Button HorizontalAlignment="Left" Click="CreatePopup"
53+
Width="150" Margin="20,10,0,0">
54+
<StackPanel Name="ButtonContentContainer">
55+
<TextBlock>Create Popup</TextBlock>
56+
</StackPanel>
57+
</Button>
58+
<!--</SnippetCreatePopupCodeXAML>-->
59+
60+
61+
62+
63+
</StackPanel>
64+
</Window>
+10-10
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ private void setColors(object sender, RoutedEventArgs e)
3636
}
3737
//</SnippetIsFocused>
3838

39-
//<SnippetCreatePopupCode>
39+
//<CreatePopup>
4040
private void CreatePopup(object sender, RoutedEventArgs e)
4141
{
42-
//<SnippetCreatePopup>
4342
Popup codePopup = new Popup();
44-
TextBlock popupText = new TextBlock();
45-
popupText.Text = "Popup Text";
46-
popupText.Background = Brushes.LightBlue;
47-
popupText.Foreground = Brushes.Blue;
43+
TextBlock popupText = new()
44+
{
45+
Text = "Popup Text",
46+
Background = Brushes.LightBlue,
47+
Foreground = Brushes.Blue
48+
};
4849
codePopup.Child = popupText;
49-
//</SnippetCreatePopup>
50-
aStackPanel.Children.Add(codePopup);
50+
ButtonContentContainer.Children.Add(codePopup);
5151
codePopup.IsOpen = true;
5252
}
53-
//</SnippetCreatePopupCode>
53+
//</CreatePopup>
5454
}
55-
}
55+
}

dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/PopupPropertiesSample.csproj

-58
This file was deleted.

dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/Window1.xaml

-64
This file was deleted.

dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PopupSimple/CSharp/sampleid.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)