Skip to content

Commit

Permalink
Added message dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleader committed Dec 3, 2021
1 parent 640a7b5 commit 98cf554
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
13 changes: 13 additions & 0 deletions WindowsAppSDKGallery/DataModel/SampleInfoDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ public sealed class SampleInfoDataSource
}
},

new SampleInfoDataGroup
{
Title = "Dialogs",
Items =
{
new SampleInfoDataItem
{
Title = "MessageDialog",
PageType = typeof(SamplePages.DialogSamples.MessageDialogPage)
}
}
},

new SampleInfoDataGroup
{
Title = "App lifecycle",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Page
x:Class="WindowsAppSDKGallery.SamplePages.DialogSamples.MessageDialogPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WindowsAppSDKGallery.SamplePages.DialogSamples"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:WindowsAppSDKGallery.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>

<controls:ApiExample
HeaderText="Content-only dialog"
x:Name="ContentOnly"
Api="new MessageDialog($content).ShowAsync();"
ExecuteApi="ContentOnly_ExecuteApi"/>

<controls:ApiExample
HeaderText="Title and content dialog"
x:Name="TitleAndContent"
Api="new MessageDialog($content, $title).ShowAsync();"
ExecuteApi="TitleAndContent_ExecuteApi"/>

</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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;
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 Windows.UI.Popups;
using WindowsAppSDKGallery.Helpers;

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

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

/// <summary>
/// Sets the HWND for the dialog so it can be displayed.
/// </summary>
/// <param name="dialog"></param>
/// <returns></returns>
private MessageDialog InitWindow(MessageDialog dialog)
{
WinRT.Interop.InitializeWithWindow.Initialize(dialog, WindowHelper.GetHwndForCurrentWindow());
return dialog;
}

private async void ContentOnly_ExecuteApi(object sender, Controls.ExecuteApiArgs e)
{
ContentOnly.IsEnabled = false;

await InitWindow(new MessageDialog(e.Parameters["content"])).ShowAsync();

ContentOnly.IsEnabled = true;
}

private async void TitleAndContent_ExecuteApi(object sender, Controls.ExecuteApiArgs e)
{
TitleAndContent.IsEnabled = false;

await InitWindow(new MessageDialog(e.Parameters["content"], e.Parameters["title"])).ShowAsync();

TitleAndContent.IsEnabled = true;
}
}
}
7 changes: 7 additions & 0 deletions WindowsAppSDKGallery/WindowsAppSDKGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<None Remove="SamplePages\AppLifecycle\PowerManagerPage.xaml" />
<None Remove="SamplePages\AppWindowSamples\BasicAppWindowSamples.xaml" />
<None Remove="SamplePages\AuthSamples\CredentialLockerPage.xaml" />
<None Remove="SamplePages\DialogSamples\MessageDialogPage.xaml" />
<None Remove="SamplePages\MediaSamples\PlaySoundsPage.xaml" />
<None Remove="SamplePages\MediaSamples\PlayVideosPage.xaml" />
<None Remove="SamplePages\ShareSamples\DataTransferManagerPage.xaml" />
Expand Down Expand Up @@ -162,4 +163,10 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<Page Update="SamplePages\DialogSamples\MessageDialogPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

0 comments on commit 98cf554

Please sign in to comment.