From c8540feeb3775dda994c3c79560bf6fac20c2a43 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 23 Jan 2024 22:48:30 +0800 Subject: [PATCH] feat: implement multi layer dialog. --- demo/Ursa.Demo/Dialogs/DialogWithAction.axaml | 7 +- .../Dialogs/DialogWithActionViewModel.cs | 9 +++ demo/Ursa.Demo/Pages/DialogDemo.axaml | 9 ++- .../ViewModels/DialogDemoViewModel.cs | 32 +++++--- src/Ursa.Themes.Semi/Controls/Dialog.axaml | 65 ++++++++++------ src/Ursa.Themes.Semi/Themes/Dark/Dialog.axaml | 5 ++ src/Ursa.Themes.Semi/Themes/Dark/_index.axaml | 1 + .../Themes/Light/Dialog.axaml | 5 ++ .../Themes/Light/_index.axaml | 1 + src/Ursa/Common/DialogIcon.cs | 15 ---- src/Ursa/Controls/Dialog/DialogBox.cs | 58 +++++++++++--- src/Ursa/Controls/Dialog/DialogControl.cs | 22 +++++- src/Ursa/Controls/Dialog/DialogOptions.cs | 5 ++ src/Ursa/Controls/Dialog/DialogWindow.cs | 25 +++--- src/Ursa/Controls/Dialog/OverlayDialogHost.cs | 76 ++++++++++++------- 15 files changed, 231 insertions(+), 104 deletions(-) create mode 100644 src/Ursa.Themes.Semi/Themes/Dark/Dialog.axaml create mode 100644 src/Ursa.Themes.Semi/Themes/Light/Dialog.axaml delete mode 100644 src/Ursa/Common/DialogIcon.cs diff --git a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml index 022fed8..b3132df 100644 --- a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml +++ b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml @@ -7,10 +7,11 @@ x:CompileBindings="True" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Ursa.Demo.Dialogs.DialogWithAction"> - - + + - + + diff --git a/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs b/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs index d5a3b58..f846146 100644 --- a/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs +++ b/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using System.Windows.Input; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -16,10 +17,13 @@ public partial class DialogWithActionViewModel: ObservableObject, IDialogContext public ICommand OKCommand { get; set; } public ICommand CancelCommand { get; set; } + public ICommand DialogCommand { get; set; } + public DialogWithActionViewModel() { OKCommand = new RelayCommand(OK); CancelCommand = new RelayCommand(Cancel); + DialogCommand = new AsyncRelayCommand(ShowDialog); Title = "Please select a date"; Date = DateTime.Now; } @@ -33,4 +37,9 @@ public partial class DialogWithActionViewModel: ObservableObject, IDialogContext { Closed?.Invoke(this, false); } + + private async Task ShowDialog() + { + await DialogBox.ShowOverlayModalAsync(new DialogWithActionViewModel(), "GlobalHost"); + } } \ No newline at end of file diff --git a/demo/Ursa.Demo/Pages/DialogDemo.axaml b/demo/Ursa.Demo/Pages/DialogDemo.axaml index 072edcb..3474c87 100644 --- a/demo/Ursa.Demo/Pages/DialogDemo.axaml +++ b/demo/Ursa.Demo/Pages/DialogDemo.axaml @@ -21,15 +21,16 @@ - - - + + + + diff --git a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs index 28b0d3f..342ab0a 100644 --- a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs @@ -11,9 +11,11 @@ namespace Ursa.Demo.ViewModels; public class DialogDemoViewModel: ObservableObject { - public ICommand ShowLocalOverlayDialogCommand { get; } + public ICommand ShowLocalOverlayModalDialogCommand { get; } + public ICommand ShowGlobalOverlayModalDialogCommand { get; } + public ICommand ShowGlobalModalDialogCommand { get; } + public ICommand ShowGlobalOverlayDialogCommand { get; } - public ICommand ShowGlobalDialogCommand { get; } private object? _result; @@ -35,27 +37,33 @@ public class DialogDemoViewModel: ObservableObject public DialogDemoViewModel() { - ShowLocalOverlayDialogCommand = new AsyncRelayCommand(ShowLocalOverlayDialog); - ShowGlobalOverlayDialogCommand = new AsyncRelayCommand(ShowGlobalOverlayDialog); - ShowGlobalDialogCommand = new AsyncRelayCommand(ShowGlobalDialog); + ShowLocalOverlayModalDialogCommand = new AsyncRelayCommand(ShowLocalOverlayModalDialog); + ShowGlobalOverlayModalDialogCommand = new AsyncRelayCommand(ShowGlobalOverlayModalDialog); + ShowGlobalModalDialogCommand = new AsyncRelayCommand(ShowGlobalModalDialog); + ShowGlobalOverlayDialogCommand = new RelayCommand(ShowGlobalOverlayDialog); } - private async Task ShowGlobalDialog() + private void ShowGlobalOverlayDialog() { - var result = await DialogBox.ShowAsync(DialogViewModel); + DialogBox.ShowOverlay(new DialogWithActionViewModel(), "GlobalHost"); + } + + private async Task ShowGlobalModalDialog() + { + var result = await DialogBox.ShowModalAsync(DialogViewModel); Result = result; } - private async Task ShowGlobalOverlayDialog() + private async Task ShowGlobalOverlayModalDialog() { - Result = await DialogBox.ShowOverlayAsync(DialogViewModel, "GlobalHost"); + Result = await DialogBox.ShowOverlayModalAsync(DialogViewModel, "GlobalHost"); } - private async Task ShowLocalOverlayDialog() + private async Task ShowLocalOverlayModalDialog() { var vm = new DialogWithActionViewModel(); - var result = await DialogBox.ShowOverlayAsync( - DialogViewModel, "LocalHost"); + var result = await DialogBox.ShowOverlayModalAsync( + DialogViewModel, "LocalHost", new DialogOptions(){ ExtendToClientArea = true }); Result = result; } } \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/Dialog.axaml b/src/Ursa.Themes.Semi/Controls/Dialog.axaml index 160f6b8..b894472 100644 --- a/src/Ursa.Themes.Semi/Controls/Dialog.axaml +++ b/src/Ursa.Themes.Semi/Controls/Dialog.axaml @@ -3,38 +3,58 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:u="https://irihi.tech/ursa"> + + + - - + + + + + + + + + + - - + DockPanel.Dock="Right" + Theme="{DynamicResource CloseButton}" /> + + @@ -69,16 +89,17 @@ - +