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

add RegisterPage #13

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.IO;
using EasyMicroservices.UI.Cores.Interfaces;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;

namespace EasyMicroservices.UI.Cores;
Expand All @@ -11,6 +14,10 @@ public abstract class NavigationManagerBase
///
/// </summary>
public static NavigationManagerBase Current { get; set; }
/// <summary>
///
/// </summary>
protected ConcurrentDictionary<string, Type> Pages { get; set; } = new ConcurrentDictionary<string, Type>();

/// <summary>
///
Expand Down Expand Up @@ -62,4 +69,13 @@ public abstract class NavigationManagerBase
/// <param name="url"></param>
/// <returns></returns>
public abstract Task<bool> OpenBrowser(string url);
/// <summary>
///
/// </summary>
/// <param name="pageName"></param>
public void RegisterPage<T>(string pageName)
where T : IPage, new()
{
Pages.TryAdd(pageName, typeof(T));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public DefaultNavigationManager(INavigation navigation)
_navigation = navigation;
}

ConcurrentDictionary<string, IPage> Pages { get; set; } = new ConcurrentDictionary<string, IPage>();
public override Task PopAsync()
{
return _navigation.PopAsync();
Expand All @@ -24,8 +23,9 @@ public override Task<TResponseData> PushAsync<TResponseData>(string pageName, bo

public override async Task<TResponseData> PushDataAsync<TData, TResponseData>(TData data, string pageName, bool doClear = false)
{
if (!Pages.TryGetValue(pageName, out IPage findPage))
if (!Pages.TryGetValue(pageName, out Type pageTpe))
throw new Exception($"Page {pageName} not found, did you register it?");
var findPage = Activator.CreateInstance(pageTpe);
Page page = findPage as Page;
if (page == null)
throw new NotImplementedException($"Page {pageName} is not inherit Page!");
Expand Down
Loading