private PageWrapper NavigateTo(PageWrapper page, int maxHistory, bool push = true, params object[] args)
 {
     try
     {
         if (ActivePage == page)
         {
             return(ActivePage);
         }
         Host.Dispatcher.InvokeEx(() =>
         {
             if (Host != null)
             {
                 var previousPage = ActivePage?.AsPage;
                 previousPage?.OnNavigateFrom(page?.AsPage);
                 _history = TrimHistory(_history, maxHistory); //just picked a number to limit the size of the history
                 if (push)
                 {
                     _history.Push(page);
                 }
                 ActivePage = page;
                 page?.AsPage?.OnNavigateTo(previousPage, args);
                 CanNavigateBack.Value = _history.Count > 1;
                 //ActivePage = page;
             }
         });
     }
     catch (Exception e)
     {
         Log.e(e);
     }
     return(page);
 }
 private static void DiscoverPages <IPageType>(Assembly asm = null)
 {
     try
     {
         if (asm == null)
         {
             asm = Assembly.GetEntryAssembly();
         }
         foreach (var t in asm.GetTypes())
         {
             if (!t.IsAbstract)
             {
                 var iface = t.GetInterfaces().FirstOrDefault(i => i == typeof(IPageType));// i.FullName == "W.WPF.Framework.IPage");
                 if (iface != null)
                 {
                     //var page = Activator.CreateInstance(t) as IPage;
                     var pw = new PageWrapper()
                     {
                         //Name = t.Name,
                         Type = t,
                         //PageXaml = t.FullName,
                         //Page = new Lazy<IPage>(() => Activator.CreateInstance(t) as IPage)
                         FrameworkElement = (FrameworkElement)Activator.CreateInstance(t)
                     };
                     AllPages.Add(pw);
                 }
             }
         }
         foreach (AssemblyName assemblyName in asm.GetReferencedAssemblies())
         {
             try
             {
                 if (assemblyName.CodeBase?.Trim('/', '\\') == AppDomain.CurrentDomain.BaseDirectory.Trim('/', '\\'))
                 //if (!assemblyName.Name.StartsWith("System") && !(assemblyName.Name.StartsWith("mscorlib")))
                 {
                     Log.i("Loading {0}", assemblyName);
                     var assembly = Assembly.Load(assemblyName.Name);
                     if (assembly != null)
                     {
                         DiscoverPages <IPageType>(assembly);
                     }
                 }
             }
             catch (Exception e)
             {
                 Log.e(e);
             }
         }
     }
     catch (Exception e)
     {
         Log.e(e);
     }
 }