Fixed issue with dialog opening but is not closing due to request running into a "ContentControlHandler" after the dialog's await state has been completed.
This commit is contained in:
@@ -3,9 +3,9 @@ using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class ContentControlNavigationHandler : IRequestHandler<ContentControlNavigation, bool>
|
||||
public class ContentControlNavigationHandler : IRequestHandler<ContentControlNavigation>
|
||||
{
|
||||
public ValueTask<bool> Handle(ContentControlNavigation request, CancellationToken cancellationToken)
|
||||
public ValueTask<Unit> Handle(ContentControlNavigation request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Template is TemplatedControl control)
|
||||
{
|
||||
@@ -13,6 +13,6 @@ public class ContentControlNavigationHandler : IRequestHandler<ContentControlNav
|
||||
request.Route.Content = control;
|
||||
}
|
||||
|
||||
return new ValueTask<bool>(true);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using System.Diagnostics;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavigation, bool>
|
||||
public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavigation>
|
||||
{
|
||||
public async ValueTask<bool> Handle(ContentDialogNavigation request, CancellationToken cancellationToken)
|
||||
public ValueTask<Unit> Handle(ContentDialogNavigation request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Template is ContentDialog contentDialog)
|
||||
{
|
||||
@@ -35,9 +36,10 @@ public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavig
|
||||
contentDialog.CloseButtonClick += HandleButtonClick;
|
||||
|
||||
contentDialog.DataContext = request.Content;
|
||||
await contentDialog.ShowAsync();
|
||||
|
||||
contentDialog.ShowAsync();
|
||||
}
|
||||
|
||||
return await Task.FromResult(true);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public class FrameNavigationHandler : IRequestHandler<FrameNavigation, bool>
|
||||
public class FrameNavigationHandler : IRequestHandler<FrameNavigation>
|
||||
{
|
||||
public async ValueTask<bool> Handle(FrameNavigation request, CancellationToken cancellationToken)
|
||||
public ValueTask<Unit> Handle(FrameNavigation request, CancellationToken cancellationToken)
|
||||
{
|
||||
request.Route.NavigationPageFactory = new NavigationPageFactory();
|
||||
|
||||
@@ -27,6 +27,6 @@ public class FrameNavigationHandler : IRequestHandler<FrameNavigation, bool>
|
||||
request.Route.NavigateFromObject(content);
|
||||
}
|
||||
|
||||
return await completionSource.Task;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using System.Diagnostics;
|
||||
using Toolkit.Controls.Avalonia;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
@@ -28,7 +29,7 @@ public class NavigateHandler : IRequestHandler<Navigate>
|
||||
this.descriptors = descriptors;
|
||||
}
|
||||
|
||||
public async ValueTask<Unit> Handle(Navigate request, CancellationToken cancellationToken)
|
||||
public ValueTask<Unit> Handle(Navigate request, CancellationToken cancellationToken)
|
||||
{
|
||||
object? content = null;
|
||||
object? template = null;
|
||||
@@ -75,20 +76,17 @@ public class NavigateHandler : IRequestHandler<Navigate>
|
||||
target = template;
|
||||
}
|
||||
|
||||
bool hasNavigated = false;
|
||||
if (target is Frame frame)
|
||||
{
|
||||
hasNavigated = await mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
|
||||
mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
|
||||
}
|
||||
|
||||
if (target is ContentDialog dialog)
|
||||
else if (target is ContentDialog dialog)
|
||||
{
|
||||
hasNavigated = await mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
|
||||
mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
|
||||
}
|
||||
|
||||
if (target is ContentControl contentControl)
|
||||
else if (target is ContentControl contentControl)
|
||||
{
|
||||
hasNavigated = await mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
|
||||
mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
public record Navigation<TRoute> : IRequest<bool> where TRoute : TemplatedControl
|
||||
public record Navigation<TRoute> : IRequest where TRoute : TemplatedControl
|
||||
{
|
||||
public TRoute Route { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user