Add some initial navigation route handlers

This commit is contained in:
Daniel Clark
2022-12-09 08:58:26 +00:00
parent fdcce769e5
commit 4c8fd3dae4
34 changed files with 403 additions and 343 deletions
@@ -0,0 +1,53 @@
using FluentAvalonia.UI.Controls;
using Mediator;
namespace Toolkit.Foundation.Avalonia
{
public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavigation, bool>
{
public async ValueTask<bool> Handle(ContentDialogNavigation request, CancellationToken cancellationToken)
{
if (request.Template is ContentDialog contentDialog)
{
async void HandleButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
ContentDialogButtonClickDeferral defferal = args.GetDeferral();
if (sender.DataContext is INavigationConfirmationAsync confirmationAsync)
{
if (!await confirmationAsync.CanConfirmAsync())
{
args.Cancel = true;
}
}
if (sender.DataContext is INavigationConfirmation confirmation)
{
if (!confirmation.CanConfirm())
{
args.Cancel = true;
}
}
if (!args.Cancel)
{
contentDialog.SecondaryButtonClick -= HandleButtonClick;
contentDialog.PrimaryButtonClick -= HandleButtonClick;
contentDialog.CloseButtonClick -= HandleButtonClick;
}
defferal.Complete();
}
contentDialog.SecondaryButtonClick += HandleButtonClick;
contentDialog.PrimaryButtonClick += HandleButtonClick;
contentDialog.CloseButtonClick += HandleButtonClick;
contentDialog.DataContext = request.Content;
await contentDialog.ShowAsync();
}
return await Task.FromResult(true);
}
}
}