Update popup code (#1111)

* Update popup code

* update xref
This commit is contained in:
Andy (Steve) De George
2021-07-19 18:35:48 -04:00
committed by GitHub
parent 5d38c60929
commit b0376d820a
9 changed files with 89 additions and 139 deletions
@@ -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();
}
}
}