Skip to content

Commit

Permalink
Add Popup Control Page (#1723)
Browse files Browse the repository at this point in the history
## Description
This pull request introduces a new page for the `Popup` control,
providing an example and details for developers to better understand and
utilize the control, main changes are:
1. Added Popup Control Details in `ControlInfoData.json`
- Included a new entry for the Popup control, with relevant descriptions
and metadata.
    - Created a New Page for the Popup Control

2. The page includes an example that demonstrates the Popup control’s
capabilities:
    - Light dismissal (IsLightDismissEnabled).
    - Offset positioning (HorizontalOffset and VerticalOffset).
- Provided detailed comments in the example code for better
understanding and usage.

## Motivation and Context
Closes #1713 

## How Has This Been Tested?
**Manually Tested**

## Screenshots (if appropriate):

![image](https://github.com/user-attachments/assets/caf93b37-523b-4980-946e-8ee7b08d0b8f)

![image](https://github.com/user-attachments/assets/132ced3d-fec8-4d20-a271-1dc561e7e4cd)

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

---------

Co-authored-by: Niels Laute <[email protected]>
  • Loading branch information
Zakariathr22 and niels9001 authored Jan 14, 2025
1 parent 82893c4 commit da694b6
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 1 deletion.
Binary file added WinUIGallery/Assets/ControlImages/Popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions WinUIGallery/ControlPages/PopupPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="WinUIGallery.ControlPages.PopupPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinUIGallery"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel>
<local:ControlExample HeaderText="Popup with Offset Positioning">
<local:ControlExample.Example>
<Grid x:Name="Output"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Button Content="Show Popup (using Offset)"
Click="ShowPopupOffsetClicked" />
<Popup VerticalOffset="{x:Bind VerticalOffset.Value , Mode=OneWay}"
HorizontalOffset="{x:Bind HorizontalOffset.Value , Mode=OneWay}"
IsLightDismissEnabled="{x:Bind IsLightDismissEnabledToggleSwitch.IsOn , Mode=OneWay}"
x:Name="StandardPopup"
Closed="PopupClosed">
<Border Padding="20"
CornerRadius="8"
Width="200"
Height="150"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
BorderThickness="1"
BorderBrush="{ThemeResource SurfaceStrokeColorDefaultBrush}">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="8">
<TextBlock Text="Simple Popup"
FontSize="16"
HorizontalAlignment="Center" />
<Button Content="Close"
Click="ClosePopupClicked" />
</StackPanel>
</Border>
</Popup>
</Grid>
</local:ControlExample.Example>
<local:ControlExample.Options>
<StackPanel Spacing="8">
<ToggleSwitch x:Name="IsLightDismissEnabledToggleSwitch"
Header="IsLightDismissEnabled"
OffContent="False"
OnContent="True"
IsOn="False"
/>
<NumberBox x:Name="VerticalOffset"
Header="VerticalOffset"
Minimum="-100"
Maximum="100"
Value="0"
SpinButtonPlacementMode="Inline"
SmallChange="10"
LargeChange="100" />
<NumberBox x:Name="HorizontalOffset"
Header="HorizontalOffset"
Minimum="-100"
Maximum="500"
Value="200"
SpinButtonPlacementMode="Inline"
SmallChange="10"
LargeChange="100" />
</StackPanel>
</local:ControlExample.Options>
<local:ControlExample.CSharp>
<x:String xml:space="preserve">
// Handles the Click event on the Button on the page and opens the Popup.
private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
{
// open the Popup if it isn't open already
if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
}

// Handles the Click event on the Button inside the Popup control and closes the Popup.
private void ClosePopupClicked(object sender, RoutedEventArgs e)
{
// if the Popup is open, then close it
if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
}
</x:String>
</local:ControlExample.CSharp>
<local:ControlExample.Xaml>
<x:String xml:space="preserve">
&lt;Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" &gt;
&lt;Button Content="Show Popup (using Offset)" Click="ShowPopupOffsetClicked" /&gt;
&lt;Popup x:Name="StandardPopup" VerticalOffset="$(VerticalOffset)" HorizontalOffset="$(HorizontalOffset)" IsLightDismissEnabled="$(IsLightDismissEnabled)"
BorderThickness="1" BorderBrush="{ThemeResource SurfaceStrokeColorDefaultBrush}"&gt;
&lt;Border Padding="20" CornerRadius="8" Width="200" Height="150"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"&gt;
&lt;StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="8"&gt;
&lt;TextBlock Text="Simple Popup" FontSize="16" HorizontalAlignment="Center" /&gt;
&lt;Button Content="Close" Click="ClosePopupClicked" /&gt;
&lt;/StackPanel&gt;
&lt;/Border&gt;
&lt;/Popup&gt;
&lt;/Grid&gt;
</x:String>
</local:ControlExample.Xaml>
<local:ControlExample.Substitutions>
<local:ControlExampleSubstitution Key="VerticalOffset" Value="{x:Bind VerticalOffset.Value, Mode=OneWay}" />
<local:ControlExampleSubstitution Key="HorizontalOffset" Value="{x:Bind HorizontalOffset.Value, Mode=OneWay}" />
<local:ControlExampleSubstitution Key="IsLightDismissEnabled" Value="{x:Bind IsLightDismissEnabledToggleSwitch.IsOn, Mode=OneWay}" />
</local:ControlExample.Substitutions>
</local:ControlExample>
</StackPanel>
</Page>
53 changes: 53 additions & 0 deletions WinUIGallery/ControlPages/PopupPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace WinUIGallery.ControlPages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class PopupPage : Page
{
public PopupPage()
{
this.InitializeComponent();
}

// Handles the Click event on the Button on the page and opens the Popup.
private void ShowPopupOffsetClicked(object sender, RoutedEventArgs e)
{
// open the Popup if it isn't open already
if (!StandardPopup.IsOpen) { StandardPopup.IsOpen = true; }
IsLightDismissEnabledToggleSwitch.IsEnabled = false;
}

// Handles the Click event on the Button inside the Popup control and
// closes the Popup.
private void ClosePopupClicked(object sender, RoutedEventArgs e)
{
// if the Popup is open, then close it
if (StandardPopup.IsOpen) { StandardPopup.IsOpen = false; }
IsLightDismissEnabledToggleSwitch.IsEnabled = true;
}

private void PopupClosed(object sender, object e)
{
IsLightDismissEnabledToggleSwitch.IsEnabled = true;
}
}
}
26 changes: 25 additions & 1 deletion WinUIGallery/DataModel/ControlInfoData.json
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,30 @@
"AppBarButton"
]
},
{
"UniqueId": "Popup",
"Title": "Popup",
"BaseClasses": [
"Object",
"DependencyObject",
"UIElement",
"FrameworkElement"
],
"ApiNamespace": "Microsoft.UI.Xaml.Controls.Primitives",
"Subtitle": "A UI element displaying temporary content over existing interface.",
"ImagePath": "ms-appx:///Assets/ControlImages/Popup.png",
"Description": "The Popup Control allows your app to display temporary content above other UI elements. It can be used for lightweight interactions such as tooltips, notifications, or custom floating panels to enhance user workflows or highlight specific parts of the interface.",
"IsNew": true,
"Docs": [
{
"Title": "Popup - API",
"Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.primitives.popup"
}
],
"RelatedControls": [
"ContentDialog"
]
},
{
"UniqueId": "TeachingTip",
"Title": "TeachingTip",
Expand Down Expand Up @@ -1751,7 +1775,7 @@
"Flyout",
"ToolTip"
]
}
}
]
},
{
Expand Down
7 changes: 7 additions & 0 deletions WinUIGallery/WinUIGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@

<ItemGroup>
<None Remove="Assets\ControlImages\Accessibility.png" />
<None Remove="Assets\ControlImages\Popup.png" />
<None Remove="Assets\Design\Cards.dark.png" />
<None Remove="Assets\Design\Cards.light.png" />
<None Remove="Assets\Design\Dialog.dark.png" />
Expand Down Expand Up @@ -315,6 +316,7 @@

<ItemGroup>
<Content Include="Assets\ControlImages\Accessibility.png" />
<Content Include="Assets\ControlImages\Popup.png" />
<Content Include="Assets\Design\Cards.dark.png" />
<Content Include="Assets\Design\Cards.light.png" />
<Content Include="Assets\Design\Dialog.dark.png" />
Expand Down Expand Up @@ -563,6 +565,11 @@
<ItemGroup>
<Folder Include="ControlPages\Accessibility\" />
</ItemGroup>
<ItemGroup>
<Page Update="ControlPages\PopupPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="ContentIncludes.props" />
<!--Per comment in Microsoft.Common.CurrentVersion.targets, the default GetCopyToPublishDirectoryItems
just returns GetCopyToOutputDirectoryItems, which automatically includes the ContentWithTargetPath
Expand Down

0 comments on commit da694b6

Please sign in to comment.