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:
Daniel Clark
2022-12-21 10:12:54 +00:00
parent e9dd86e0e0
commit b8e50e4dc0
8 changed files with 25 additions and 24 deletions
+1
View File
@@ -11,6 +11,7 @@
<PackageReference Include="FluentAvaloniaUI" Version="2.0.0-preview4" /> <PackageReference Include="FluentAvaloniaUI" Version="2.0.0-preview4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Controls\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\Foundation\Foundation.csproj" /> <ProjectReference Include="..\Foundation\Foundation.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -463,12 +463,12 @@ public class NavigateExtension : TriggerExtension
name = string.Format(format, name); name = string.Format(format, name);
} }
mediator.Send(new Navigate(name, parameters.ToArray()) { Route = route }); mediator.Send(new Navigate(name, parameters.ToArray()) { Route = route }).ConfigureAwait(false);
} }
if (to is Type type) if (to is Type type)
{ {
mediator.Send(new Navigate(type, parameters.ToArray()) { Route = route }); mediator.Send(new Navigate(type, parameters.ToArray()) { Route = route }).ConfigureAwait(false);
} }
} }
} }
@@ -3,9 +3,9 @@ using Toolkit.Framework.Foundation;
namespace Toolkit.Framework.Avalonia; 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) if (request.Template is TemplatedControl control)
{ {
@@ -13,6 +13,6 @@ public class ContentControlNavigationHandler : IRequestHandler<ContentControlNav
request.Route.Content = control; request.Route.Content = control;
} }
return new ValueTask<bool>(true); return default;
} }
} }
@@ -1,11 +1,12 @@
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using System.Diagnostics;
using Toolkit.Framework.Foundation; using Toolkit.Framework.Foundation;
namespace Toolkit.Framework.Avalonia; 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) if (request.Template is ContentDialog contentDialog)
{ {
@@ -35,9 +36,10 @@ public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavig
contentDialog.CloseButtonClick += HandleButtonClick; contentDialog.CloseButtonClick += HandleButtonClick;
contentDialog.DataContext = request.Content; 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; 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(); request.Route.NavigationPageFactory = new NavigationPageFactory();
@@ -27,6 +27,6 @@ public class FrameNavigationHandler : IRequestHandler<FrameNavigation, bool>
request.Route.NavigateFromObject(content); request.Route.NavigateFromObject(content);
} }
return await completionSource.Task; return default;
} }
} }
@@ -1,5 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using FluentAvalonia.UI.Controls; using System.Diagnostics;
using Toolkit.Controls.Avalonia;
using Toolkit.Framework.Foundation; using Toolkit.Framework.Foundation;
namespace Toolkit.Framework.Avalonia; namespace Toolkit.Framework.Avalonia;
@@ -28,7 +29,7 @@ public class NavigateHandler : IRequestHandler<Navigate>
this.descriptors = descriptors; this.descriptors = descriptors;
} }
public async ValueTask<Unit> Handle(Navigate request, CancellationToken cancellationToken) public ValueTask<Unit> Handle(Navigate request, CancellationToken cancellationToken)
{ {
object? content = null; object? content = null;
object? template = null; object? template = null;
@@ -75,20 +76,17 @@ public class NavigateHandler : IRequestHandler<Navigate>
target = template; target = template;
} }
bool hasNavigated = false;
if (target is Frame frame) if (target is Frame frame)
{ {
hasNavigated = await mediator.Send(new FrameNavigation(frame, content, template, keyedParameters)); mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
} }
else if (target is ContentDialog dialog)
if (target is ContentDialog dialog)
{ {
hasNavigated = await mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters)); mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
} }
else if (target is ContentControl contentControl)
if (target is ContentControl contentControl)
{ {
hasNavigated = await mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters)); mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
} }
} }
else else
+1 -1
View File
@@ -3,7 +3,7 @@ using Toolkit.Framework.Foundation;
namespace Toolkit.Framework.Avalonia; 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; } public TRoute Route { get; }
@@ -8,7 +8,7 @@ public class RequestClassHandlerWrapper<TRequest, TResponse> where TRequest : cl
IEnumerable<IPipelineBehavior<TRequest, TResponse>> pipelineBehaviours) IEnumerable<IPipelineBehavior<TRequest, TResponse>> pipelineBehaviours)
{ {
MessageHandlerDelegate<TRequest, TResponse> handler = concreteHandler.Handle; MessageHandlerDelegate<TRequest, TResponse> handler = concreteHandler.Handle;
foreach (var pipeline in pipelineBehaviours.Reverse()) foreach (IPipelineBehavior<TRequest, TResponse>? pipeline in pipelineBehaviours.Reverse())
{ {
MessageHandlerDelegate<TRequest, TResponse> handlerCopy = handler; MessageHandlerDelegate<TRequest, TResponse> handlerCopy = handler;
IPipelineBehavior<TRequest, TResponse> pipelineCopy = pipeline; IPipelineBehavior<TRequest, TResponse> pipelineCopy = pipeline;