Skip to content

Commit 23229e9

Browse files
committed
Added sample for AppDialog
1 parent 1ecfb72 commit 23229e9

11 files changed

Lines changed: 184 additions & 23 deletions

File tree

assets/SampleIcons.afdesign

903 Bytes
Binary file not shown.

samples/MADE.Samples/MADE.Samples.Shared/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace MADE.Samples
77
using MADE.Diagnostics.Logging;
88
using MADE.Samples.Features.Home.Pages;
99
using MADE.Samples.Infrastructure.ViewModels;
10+
using MADE.UI.Views.Dialogs;
1011
using MADE.UI.Views.Navigation;
1112
using Microsoft.Extensions.DependencyInjection;
1213
using Windows.ApplicationModel.Activation;
@@ -52,6 +53,7 @@ private static IServiceProvider ConfigureServices(Frame rootFrame)
5253
Ioc.Default.ConfigureServices(
5354
new ServiceCollection()
5455
.AddSingleton<IMessenger>(provider => WeakReferenceMessenger.Default)
56+
.AddSingleton<IAppDialog>(provider => new AppDialog(rootFrame.Dispatcher))
5557
.AddSingleton<IEventLogger, FileEventLogger>()
5658
.AddSingleton<IAppDiagnostics, AppDiagnostics>()
5759
.AddSingleton<INavigationService>(provider => new NavigationService(rootFrame))
3.54 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
private async Task ShowAppDialogAsync()
2+
{
3+
// This can be registered globally in a service collection and made available through dependency injection.
4+
IAppDialog appDialog = new AppDialog(this.Dispatcher);
5+
6+
await appDialog.ShowAsync(
7+
"Title",
8+
"Message",
9+
() => { Console.WriteLine("App dialog was dismissed!") },
10+
new DialogButton(DialogButtonType.Confirm)
11+
{
12+
Content = "Confirm",
13+
InvokeAction = button => Console.WriteLine("App dialog confirm button clicked!")
14+
},
15+
new DialogButton(DialogButtonType.Cancel)
16+
{
17+
Content = "Cancel",
18+
InvokeAction = button => Console.WriteLine("App dialog cancel button clicked!")
19+
},
20+
new DialogButton(DialogButtonType.Neutral)
21+
{
22+
Content = "Help",
23+
InvokeAction = button => Console.WriteLine("App dialog help button clicked!")
24+
});
25+
}

samples/MADE.Samples/MADE.Samples.Shared/Features/Samples/Pages/AppDialogPage.xaml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
x:Class="MADE.Samples.Features.Samples.Pages.AppDialogPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:controls="using:MADE.UI.Controls"
65
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
76
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
87
xmlns:pages="using:MADE.UI.Views.Navigation.Pages"
8+
xmlns:samples="using:MADE.Samples.Infrastructure.Controls"
99
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1010
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
1111
mc:Ignorable="d">
@@ -44,18 +44,42 @@
4444
Grid.Row="1"
4545
Margin="0,0,0,48"
4646
Style="{StaticResource BaseTextBlockStyle}"
47-
Text="The FilePicker is a custom-built UI element that provides a file selection user experience. The control works in a similar way to the file input element in web applications." />
47+
Text="The AppDialog is a UI helper that provides a mechanism to simplify the showing of application modal dialogs." />
4848

4949
<ScrollViewer Grid.Row="2">
5050
<Grid>
51-
<!--<controls:FilePicker
52-
x:Name="FilePickerControl"
53-
Margin="0,16,0,0"
54-
AppendFiles="True"
55-
FileTypes="{x:Bind ViewModel.FilePickerTypes}"
56-
Files="{x:Bind ViewModel.FilePickerFiles}"
57-
Header="FilePicker with multiple item selection"
58-
SelectionMode="Multiple" />-->
51+
<samples:SampleControl CodeSource="AppDialog/AppDialogCode.txt" SampleName="Show a modal dialog from anywhere using a title, message, and actionable buttons">
52+
<samples:SampleControl.Sample>
53+
<StackPanel>
54+
<TextBox
55+
Margin="0,0,0,16"
56+
Header="Set title"
57+
Text="{x:Bind ViewModel.AppDialogTitle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
58+
<TextBox
59+
Margin="0,0,0,16"
60+
Header="Set message"
61+
Text="{x:Bind ViewModel.AppDialogMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
62+
<TextBox
63+
Margin="0,0,0,16"
64+
Header="Set confirm button content"
65+
Text="{x:Bind ViewModel.AppDialogConfirmText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
66+
<TextBox
67+
Margin="0,0,0,16"
68+
Header="Set cancel button content"
69+
Text="{x:Bind ViewModel.AppDialogCancelText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
70+
<TextBox
71+
Margin="0,0,0,16"
72+
Header="Set additional button content"
73+
Text="{x:Bind ViewModel.AppDialogNeutralText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
74+
<Button
75+
Margin="0,0,0,16"
76+
Command="{x:Bind ViewModel.ShowAppDialogCommand}"
77+
Content="Show app dialog" />
78+
79+
<TextBlock Text="{x:Bind ViewModel.AppDialogResponseMessage, Mode=OneWay}" />
80+
</StackPanel>
81+
</samples:SampleControl.Sample>
82+
</samples:SampleControl>
5983
</Grid>
6084
</ScrollViewer>
6185

samples/MADE.Samples/MADE.Samples.Shared/Features/Samples/Pages/AppDialogPage.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace MADE.Samples.Features.Samples.Pages
22
{
33
using CommunityToolkit.Mvvm.Messaging;
44
using MADE.Samples.Features.Samples.ViewModels;
5+
using MADE.UI.Views.Dialogs;
56
using MADE.UI.Views.Navigation;
67
using MADE.UI.Views.Navigation.Pages;
78
using Microsoft.Extensions.DependencyInjection;
@@ -12,6 +13,7 @@ public AppDialogPage()
1213
{
1314
this.InitializeComponent();
1415
this.DataContext = new AppDialogPageViewModel(
16+
App.Services.GetService<IAppDialog>(),
1517
App.Services.GetService<INavigationService>(),
1618
App.Services.GetService<IMessenger>());
1719
}

samples/MADE.Samples/MADE.Samples.Shared/Features/Samples/Pages/FilePickerPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<TextBlock
4040
Margin="0,0,0,16"
4141
Style="{StaticResource TitleTextBlockStyle}"
42-
Text="FilePicker" />
42+
Text="FilePicker control" />
4343

4444
<TextBlock
4545
Grid.Row="1"
Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,111 @@
11
namespace MADE.Samples.Features.Samples.ViewModels
22
{
3+
using System;
4+
using System.Threading.Tasks;
5+
using System.Windows.Input;
6+
using CommunityToolkit.Mvvm.Input;
37
using CommunityToolkit.Mvvm.Messaging;
8+
using MADE.UI.Views.Dialogs;
9+
using MADE.UI.Views.Dialogs.Buttons;
410
using MADE.UI.Views.Navigation;
511
using MADE.UI.Views.Navigation.ViewModels;
612

713
public class AppDialogPageViewModel : PageViewModel
814
{
9-
public AppDialogPageViewModel(INavigationService navigationService, IMessenger messenger)
15+
private readonly IAppDialog appDialog;
16+
private string appDialogTitle = "Alert";
17+
private string appDialogMessage = "This is an app dialog!";
18+
private string appDialogConfirmText = "Confirm";
19+
private string appDialogCancelText = "Cancel";
20+
private string appDialogNeutralText = "Help";
21+
private string appDialogResponseMessage;
22+
23+
public AppDialogPageViewModel(IAppDialog appDialog, INavigationService navigationService, IMessenger messenger)
1024
: base(navigationService, messenger)
1125
{
26+
this.appDialog = appDialog;
27+
}
28+
29+
public ICommand ShowAppDialogCommand => new AsyncRelayCommand(this.ShowAppDialogAsync);
30+
31+
public string AppDialogTitle
32+
{
33+
get => appDialogTitle;
34+
set => SetProperty(ref appDialogTitle, value);
35+
}
36+
37+
public string AppDialogMessage
38+
{
39+
get => appDialogMessage;
40+
set => SetProperty(ref appDialogMessage, value);
41+
}
42+
43+
public string AppDialogConfirmText
44+
{
45+
get => appDialogConfirmText;
46+
set => SetProperty(ref appDialogConfirmText, value);
47+
}
48+
49+
public string AppDialogCancelText
50+
{
51+
get => appDialogCancelText;
52+
set => SetProperty(ref appDialogCancelText, value);
1253
}
1354

55+
public string AppDialogNeutralText
56+
{
57+
get => appDialogNeutralText;
58+
set => SetProperty(ref appDialogNeutralText, value);
59+
}
60+
61+
public string AppDialogResponseMessage
62+
{
63+
get => appDialogResponseMessage;
64+
set => SetProperty(ref appDialogResponseMessage, value);
65+
}
66+
67+
private async Task ShowAppDialogAsync()
68+
{
69+
await appDialog.ShowAsync(
70+
AppDialogTitle,
71+
AppDialogMessage,
72+
OnAppDialogCancelled,
73+
new DialogButton(DialogButtonType.Confirm)
74+
{
75+
Content = AppDialogConfirmText,
76+
InvokeAction = button => Console.WriteLine("")
77+
},
78+
new DialogButton(DialogButtonType.Cancel)
79+
{
80+
Content = AppDialogCancelText,
81+
InvokeAction = this.OnDialogButtonInvoked
82+
},
83+
new DialogButton(DialogButtonType.Neutral)
84+
{
85+
Content = AppDialogNeutralText,
86+
InvokeAction = this.OnDialogButtonInvoked
87+
});
88+
}
89+
90+
private void OnDialogButtonInvoked(DialogButton button)
91+
{
92+
switch (button.Type)
93+
{
94+
case DialogButtonType.Confirm:
95+
this.AppDialogResponseMessage = "App dialog confirm button clicked!";
96+
break;
97+
case DialogButtonType.Cancel:
98+
this.AppDialogResponseMessage = "App dialog cancel button clicked!";
99+
break;
100+
case DialogButtonType.Neutral:
101+
this.AppDialogResponseMessage = "App dialog additional button clicked!";
102+
break;
103+
}
104+
}
105+
106+
private void OnAppDialogCancelled()
107+
{
108+
this.AppDialogResponseMessage = "App dialog was dismissed";
109+
}
14110
}
15111
}

samples/MADE.Samples/MADE.Samples.Shared/Infrastructure/Controls/SampleControl.xaml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
Style="{ThemeResource SubtitleTextBlockStyle}"
2020
Text="{x:Bind SampleName}" />
2121

22-
<TextBlock
22+
<Grid
2323
Grid.Row="1"
24-
Margin="0,0,0,16"
25-
Style="{ThemeResource BaseTextBlockStyle}"
26-
Text="{x:Bind SampleDescription}" />
27-
28-
<Grid Grid.Row="2">
24+
Background="#F0F0F0"
25+
BorderBrush="#E9E9E9"
26+
BorderThickness="2"
27+
CornerRadius="8">
2928
<Grid.RowDefinitions>
3029
<RowDefinition Height="Auto" />
3130
<RowDefinition Height="Auto" />
@@ -34,19 +33,25 @@
3433

3534
<ContentPresenter
3635
x:Name="SamplePresenter"
37-
Margin="0,0,0,16"
36+
Padding="16"
3837
HorizontalAlignment="Stretch"
3938
VerticalAlignment="Stretch"
4039
HorizontalContentAlignment="Stretch"
41-
BorderBrush="{ThemeResource SystemControlBackgroundListLowBrush}"
4240
Content="{x:Bind Sample}" />
4341

4442
<Grid
4543
x:Name="SampleXamlPresenter"
4644
Grid.Row="1"
47-
Margin="0,0,0,16" />
45+
Padding="16"
46+
Background="#F9F9F9"
47+
Visibility="Collapsed" />
4848

49-
<Grid x:Name="SampleCodePresenter" Grid.Row="2" />
49+
<Grid
50+
x:Name="SampleCodePresenter"
51+
Grid.Row="2"
52+
Padding="16"
53+
Background="#F9F9F9"
54+
Visibility="Collapsed" />
5055
</Grid>
5156
</Grid>
5257
</UserControl>

samples/MADE.Samples/MADE.Samples.Shared/Infrastructure/Controls/SampleControl.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ private async Task GenerateSyntaxHighlightedContentFromFileAsync(Uri source, Pan
160160
{
161161
if (source != null && source.AbsolutePath.EndsWith("txt"))
162162
{
163+
presenter.Visibility = Visibility.Visible;
164+
163165
var absoluteSourceUri = GetApplicationSourceUri(source);
164166
var file = await StorageFile.GetFileFromApplicationUriAsync(absoluteSourceUri);
165167
var content = await FileIO.ReadTextAsync(file);

0 commit comments

Comments
 (0)