Fixed more edge cases

This commit is contained in:
TheXamlGuy
2024-05-16 21:41:48 +01:00
parent 8c0436644a
commit 7f3c4c53cc
16 changed files with 93 additions and 33 deletions
+21 -19
View File
@@ -10,8 +10,11 @@ public class NavigationScope(IPublisher publisher,
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
INavigationScope
{
public void Navigate(string route, object? sender = null, object? context = null,
EventHandler? navigated = null, object[]? parameters = null)
public void Navigate(string route,
object? sender = null,
object? context = null,
EventHandler? navigated = null,
object[]? parameters = null)
{
string[] segments = route.Split('/');
int segmentCount = segments.Length;
@@ -41,26 +44,25 @@ public class NavigationScope(IPublisher publisher,
if (provider.GetRequiredKeyedService(descriptor.TemplateType, segment) is object view)
{
if ((parameters is { Length: > 0 }
if (context is not null)
{
if (navigationContextProvider.TryGet(context, out object? scopedContext))
{
context = scopedContext;
}
}
else
{
context = view;
}
if (context is not null)
{
if ((parameters is { Length: > 0 }
? factory.Create(descriptor.ContentType, parameters)
: provider.GetRequiredKeyedService(descriptor.ContentType, segment)) is object viewModel)
{
if (context is not null)
{
if (navigationContextProvider.TryGet(context, out object? scopedContext))
{
context = scopedContext;
}
}
else
{
context = view;
}
if (context is not null)
{
if (navigationProvider.Get(context is Type type ? type : context.GetType())
is INavigation navigation)
if (navigationProvider.Get(context is Type type ? type : context.GetType()) is INavigation navigation)
{
Type navigateType = typeof(NavigateEventArgs<>).MakeGenericType(navigation.Type);
if (Activator.CreateInstance(navigateType, [context, view, viewModel, sender, parameters]) is object navigate)