From 5c62131a0a744f6ec397b29d1222c4ee402b38a1 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 22 Jan 2024 17:27:11 +0800 Subject: [PATCH] feat: implement closing related features. --- .../ViewModels/DialogDemoViewModel.cs | 6 +-- src/Ursa.Themes.Semi/Controls/Dialog.axaml | 46 +++++++++++++------ src/Ursa/Controls/Dialog/DialogBox.cs | 2 +- src/Ursa/Controls/Dialog/DialogControl.cs | 23 +++++++++- ...erlayDialogOptions.cs => DialogOptions.cs} | 2 +- src/Ursa/Controls/Dialog/OverlayDialogHost.cs | 11 +++++ 6 files changed, 70 insertions(+), 20 deletions(-) rename src/Ursa/Controls/Dialog/{OverlayDialogOptions.cs => DialogOptions.cs} (70%) diff --git a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs index 9fe6f00..f1ca5f6 100644 --- a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs @@ -1,8 +1,6 @@ using System; using System.Threading.Tasks; using System.Windows.Input; -using Avalonia.Controls; -using Avalonia.Controls.Shapes; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Ursa.Controls; @@ -30,11 +28,11 @@ public class DialogDemoViewModel: ObservableObject private async Task ShowGlobalOverlayDialog() { - await DialogBox.ShowOverlayAsync(DateTime.Now, "GlobalHost"); + await DialogBox.ShowOverlayAsync(new ButtonGroupDemoViewModel(), "GlobalHost"); } private async Task ShowLocalOverlayDialog() { - await DialogBox.ShowOverlayAsync(DateTime.Now, "LocalHost"); + await DialogBox.ShowOverlayAsync(new ButtonGroupDemoViewModel(), "LocalHost"); } } \ 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 62355cb..6774e5c 100644 --- a/src/Ursa.Themes.Semi/Controls/Dialog.axaml +++ b/src/Ursa.Themes.Semi/Controls/Dialog.axaml @@ -1,19 +1,35 @@ - - + + - + - + + + + + + + + - + @@ -26,11 +42,15 @@ - + - - Full - BorderOnly + + + Full + + + BorderOnly + @@ -40,10 +60,10 @@ - + - + diff --git a/src/Ursa/Controls/Dialog/DialogBox.cs b/src/Ursa/Controls/Dialog/DialogBox.cs index f92e848..90e68d7 100644 --- a/src/Ursa/Controls/Dialog/DialogBox.cs +++ b/src/Ursa/Controls/Dialog/DialogBox.cs @@ -58,7 +58,7 @@ public static class DialogBox }; t.DataContext = vm; var host = OverlayDialogManager.GetOverlayDialogHost(hostId); - host?.Children.Add(t); + host?.AddDialog(t); return null; } } \ No newline at end of file diff --git a/src/Ursa/Controls/Dialog/DialogControl.cs b/src/Ursa/Controls/Dialog/DialogControl.cs index e3cae7a..d544674 100644 --- a/src/Ursa/Controls/Dialog/DialogControl.cs +++ b/src/Ursa/Controls/Dialog/DialogControl.cs @@ -13,15 +13,36 @@ public class DialogControl: ContentControl private Button? _closeButton; - public event EventHandler OnClose; + public event EventHandler OnClose; protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); + if (_closeButton != null) + { + _closeButton.Click -= Close; + } + _closeButton = e.NameScope.Find