Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-generic register for navigation with view-model #2257

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Forms/Prism.Forms/Ioc/IContainerRegistryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public static void RegisterForNavigation<TView, TViewModel>(this IContainerRegis
containerRegistry.RegisterForNavigationWithViewModel<TViewModel>(typeof(TView), name);
}

/// <summary>
/// Registers a Page for navigation.
/// </summary>
/// <param name="viewType">The Type of Page to register</param>
/// <param name="viewModelType">The Type of ViewModel to use as the BindingContext for the Page</param>
/// <param name="name">The unique name to register with the Page</param>
/// <param name="containerRegistry"></param>
public static void RegisterForNavigation(this IContainerRegistry containerRegistry, Type viewType, Type viewModelType, string name = null)
{
containerRegistry.RegisterForNavigationWithViewModel(viewType, viewModelType, name);
}

/// <summary>
/// Registers a Page for navigation based on the current Device OS using a shared ViewModel
/// </summary>
Expand Down Expand Up @@ -175,11 +187,16 @@ public static void RegisterForNavigationOnIdiom<TView, TViewModel>(this IContain

private static void RegisterForNavigationWithViewModel<TViewModel>(this IContainerRegistry containerRegistry, Type viewType, string name)
where TViewModel : class
{
containerRegistry.RegisterForNavigationWithViewModel(viewType, typeof(TViewModel), name);
}

private static void RegisterForNavigationWithViewModel(this IContainerRegistry containerRegistry, Type viewType, Type viewModelType, string name)
{
if (string.IsNullOrWhiteSpace(name))
name = viewType.Name;

ViewModelLocationProvider.Register(viewType.ToString(), typeof(TViewModel));
ViewModelLocationProvider.Register(viewType.ToString(), viewModelType);

containerRegistry.RegisterForNavigation(viewType, name);
}
Expand Down