提交 5891f002 编写于 作者: D Dan Siegel

chore: removing duplicate platform extensions

上级 84cbb447
...@@ -8,7 +8,7 @@ public class MauiTestRegionsModule : IModule ...@@ -8,7 +8,7 @@ public class MauiTestRegionsModule : IModule
public void OnInitialized(IContainerProvider containerProvider) public void OnInitialized(IContainerProvider containerProvider)
{ {
var regionManager = containerProvider.Resolve<IRegionManager>(); var regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("ContentRegion", "RegionViewA"); regionManager.RegisterViewWithRegion<RegionViewA>("ContentRegion");
} }
public void RegisterTypes(IContainerRegistry containerRegistry) public void RegisterTypes(IContainerRegistry containerRegistry)
...@@ -23,4 +23,4 @@ public class MauiTestRegionsModule : IModule ...@@ -23,4 +23,4 @@ public class MauiTestRegionsModule : IModule
.RegisterForRegionNavigation<RegionViewB, RegionViewBViewModel>() .RegisterForRegionNavigation<RegionViewB, RegionViewBViewModel>()
.RegisterForRegionNavigation<RegionViewC, RegionViewCViewModel>(); .RegisterForRegionNavigation<RegionViewC, RegionViewCViewModel>();
} }
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ public abstract class RegionViewModelBase : BindableBase, IRegionAware, IPageLif ...@@ -15,7 +15,7 @@ public abstract class RegionViewModelBase : BindableBase, IRegionAware, IPageLif
_pageAccessor = pageAccessor; _pageAccessor = pageAccessor;
} }
public bool IsNavigationTarget(INavigationContext navigationContext) => public bool IsNavigationTarget(NavigationContext navigationContext) =>
navigationContext.NavigatedName() == Name; navigationContext.NavigatedName() == Name;
private string? _message; private string? _message;
...@@ -34,12 +34,12 @@ public abstract class RegionViewModelBase : BindableBase, IRegionAware, IPageLif ...@@ -34,12 +34,12 @@ public abstract class RegionViewModelBase : BindableBase, IRegionAware, IPageLif
public string? PageName => _pageAccessor.Page?.GetType()?.Name; public string? PageName => _pageAccessor.Page?.GetType()?.Name;
public void OnNavigatedFrom(INavigationContext navigationContext) public void OnNavigatedFrom(NavigationContext navigationContext)
{ {
} }
public void OnNavigatedTo(INavigationContext navigationContext) public void OnNavigatedTo(NavigationContext navigationContext)
{ {
if (navigationContext.Parameters.ContainsKey(nameof(Message))) if (navigationContext.Parameters.ContainsKey(nameof(Message)))
Message = navigationContext.Parameters.GetValue<string>(nameof(Message)); Message = navigationContext.Parameters.GetValue<string>(nameof(Message));
......
using Prism.Navigation;
using Prism.Regions.Navigation;
namespace Prism.Regions;
/// <summary>
/// NavigationExtensions for the <see cref="IRegionManager" />
/// </summary>
public static class IRegionManagerExtensions
{
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="regionManager">The navigation object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">The navigation target</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, string target)
{
RequestNavigate(regionManager, regionName, target, nr => { });
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="regionManager">The navigation object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">The navigation target</param>
/// <param name="navigationCallback">The callback executed when the navigation request is completed.</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, string target, Action<NavigationResult> navigationCallback)
{
if (regionManager == null)
throw new ArgumentNullException(nameof(regionManager));
if (target == null)
throw new ArgumentNullException(nameof(target));
var targetUri = new Uri(target, UriKind.RelativeOrAbsolute);
regionManager.RequestNavigate(regionName, targetUri, navigationCallback);
}
/// <summary>
/// Initiates navigation to the target specified by the <see cref="Uri"/>.
/// </summary>
/// <param name="regionManager">The navigation object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">The navigation target</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, Uri target)
{
if (regionManager == null)
throw new ArgumentNullException(nameof(regionManager));
regionManager.RequestNavigate(regionName, target, nr => { });
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="regionManager">The navigation object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">The navigation target</param>
/// <param name="navigationCallback">The callback executed when the navigation request is completed.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, string target, Action<NavigationResult> navigationCallback, INavigationParameters regionParameters)
{
if (regionManager == null)
throw new ArgumentNullException(nameof(regionManager));
if (target == null)
throw new ArgumentNullException(nameof(target));
var targetUri = new Uri(target, UriKind.RelativeOrAbsolute);
regionManager.RequestNavigate(regionName, targetUri, navigationCallback, regionParameters);
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="regionManager">The RegionManager object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">A Uri that represents the target where the region will navigate.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, Uri target, INavigationParameters regionParameters)
{
if (regionManager == null)
throw new ArgumentNullException(nameof(regionManager));
regionManager.RequestNavigate(regionName, target, nr => { }, regionParameters);
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="regionManager">The RegionManager object.</param>
/// <param name="regionName">The name of the Region to navigate to.</param>
/// <param name="target">A string that represents the target where the region will navigate.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this IRegionManager regionManager, string regionName, string target, INavigationParameters regionParameters)
{
if (regionManager == null)
throw new ArgumentNullException(nameof(regionManager));
if (target == null)
throw new ArgumentNullException(nameof(target));
regionManager.RequestNavigate(regionName, new Uri(target, UriKind.RelativeOrAbsolute), nr => { }, regionParameters);
}
/// <summary>
/// Associate a view with a region, by registering a type. When the region get's displayed
/// this type will be resolved using the ServiceLocator into a concrete instance. The instance
/// will be added to the Views collection of the region
/// </summary>
/// <typeparam name="T">The type of the view to register with the <see cref="IRegion"/>.</typeparam>
/// <param name="regionManager">The current <see cref="IRegionManager"/>.</param>
/// <param name="regionName">The name of the region to associate the view with.</param>
/// <returns>The <see cref="IRegionManager"/>, for adding several views easily</returns>
public static IRegionManager RegisterViewWithRegion<T>(this IRegionManager regionManager, string regionName) =>
regionManager.RegisterViewWithRegion(regionName, typeof(T));
}
using Prism.Navigation;
namespace Prism.Regions.Navigation;
/// <summary>
/// Provides additional methods to the <see cref="INavigateAsync"/> interface.
/// </summary>
public static class NavigationAsyncExtensions
{
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">The navigation target</param>
public static void RequestNavigate(this INavigateAsync navigation, string target)
{
RequestNavigate(navigation, target, nr => { });
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">The navigation target</param>
/// <param name="navigationCallback">The callback executed when the navigation request is completed.</param>
public static void RequestNavigate(this INavigateAsync navigation, string target, Action<NavigationResult> navigationCallback)
{
if (navigation == null)
throw new ArgumentNullException(nameof(navigation));
if (target == null)
throw new ArgumentNullException(nameof(target));
var targetUri = new Uri(target, UriKind.RelativeOrAbsolute);
navigation.RequestNavigate(targetUri, navigationCallback);
}
/// <summary>
/// Initiates navigation to the target specified by the <see cref="Uri"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">The navigation target</param>
public static void RequestNavigate(this INavigateAsync navigation, Uri target)
{
if (navigation == null)
throw new ArgumentNullException(nameof(navigation));
navigation.RequestNavigate(target, nr => { });
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">The navigation target</param>
/// <param name="navigationCallback">The callback executed when the navigation request is completed.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this INavigateAsync navigation, string target, Action<NavigationResult> navigationCallback, INavigationParameters regionParameters)
{
if (navigation == null)
throw new ArgumentNullException(nameof(navigation));
if (target == null)
throw new ArgumentNullException(nameof(target));
var targetUri = new Uri(target, UriKind.RelativeOrAbsolute);
navigation.RequestNavigate(targetUri, navigationCallback, regionParameters);
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">A Uri that represents the target where the region will navigate.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this INavigateAsync navigation, Uri target, INavigationParameters regionParameters)
{
if (navigation == null)
throw new ArgumentNullException(nameof(navigation));
navigation.RequestNavigate(target, nr => { }, regionParameters);
}
/// <summary>
/// Initiates navigation to the target specified by the <paramref name="target"/>.
/// </summary>
/// <param name="navigation">The navigation object.</param>
/// <param name="target">A string that represents the target where the region will navigate.</param>
/// <param name="regionParameters">An instance of NavigationParameters, which holds a collection of object parameters.</param>
public static void RequestNavigate(this INavigateAsync navigation, string target, INavigationParameters regionParameters)
{
if (navigation == null)
throw new ArgumentNullException(nameof(navigation));
if (target == null)
throw new ArgumentNullException(nameof(target));
navigation.RequestNavigate(new Uri(target, UriKind.RelativeOrAbsolute), nr => { }, regionParameters);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册