|
@@ -1,4 +1,6 @@
|
|
|
using System;
|
|
|
+using System.Diagnostics.Tracing;
|
|
|
+using DialogHostAvalonia;
|
|
|
using InABox.Avalonia.Components;
|
|
|
using InABox.Avalonia.Router;
|
|
|
|
|
@@ -14,6 +16,16 @@ public interface IViewModelBase
|
|
|
AvaloniaMenuItemCollection SecondaryMenu { get; set; }
|
|
|
}
|
|
|
|
|
|
+public interface IPopupViewModel
|
|
|
+{
|
|
|
+ bool IsClosed { get; }
|
|
|
+}
|
|
|
+
|
|
|
+public interface IPopupViewModel<TResult> : IPopupViewModel
|
|
|
+{
|
|
|
+ TResult? GetResult();
|
|
|
+}
|
|
|
+
|
|
|
public static class Navigation
|
|
|
{
|
|
|
private static readonly HistoryRouter<IViewModelBase> _router;
|
|
@@ -35,6 +47,46 @@ public static class Navigation
|
|
|
_router.GoTo<T>(configure);
|
|
|
}
|
|
|
|
|
|
+ public static async Task<object?> Popup<T>(Action<T>? configure = null, bool canTapAway = true)
|
|
|
+ where T : IViewModelBase, IPopupViewModel
|
|
|
+ {
|
|
|
+ var viewModel = _router.InstantiateViewModel<T>(configure);
|
|
|
+ return await Popup(viewModel, canTapAway);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async Task<object?> Popup<T>(T viewModel, bool canTapAway = true)
|
|
|
+ where T : IViewModelBase, IPopupViewModel
|
|
|
+ {
|
|
|
+ var _result = await DialogHostAvalonia.DialogHost.Show(viewModel, (object sender, DialogClosingEventArgs eventArgs) =>
|
|
|
+ {
|
|
|
+ if(!canTapAway && !viewModel.IsClosed)
|
|
|
+ {
|
|
|
+ eventArgs.Cancel();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async Task<TResult?> Popup<T, TResult>(Action<T>? configure = null, bool canTapAway = true)
|
|
|
+ where T : IViewModelBase, IPopupViewModel<TResult>
|
|
|
+ {
|
|
|
+ var viewModel = _router.InstantiateViewModel<T>(configure);
|
|
|
+ return await Popup<T, TResult>(viewModel, canTapAway);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async Task<TResult?> Popup<T, TResult>(T viewModel, bool canTapAway = true)
|
|
|
+ where T : IViewModelBase, IPopupViewModel<TResult>
|
|
|
+ {
|
|
|
+ var _result = await DialogHostAvalonia.DialogHost.Show(viewModel, (object sender, DialogClosingEventArgs eventArgs) =>
|
|
|
+ {
|
|
|
+ if(!canTapAway && !viewModel.IsClosed)
|
|
|
+ {
|
|
|
+ eventArgs.Cancel();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return viewModel.GetResult();
|
|
|
+ }
|
|
|
+
|
|
|
public static void Reset<T>(Action<T>? configure = null) where T : IViewModelBase
|
|
|
{
|
|
|
_router.Reset<T>(configure);
|