Ejemplo n.º 1
0
        public void Should_find_Page_Type()
        {
            var xaml = XAMLTests.CustomPageType;
            var er   = new XamlDocumentDiscovery(xaml);

            var pageName = er.GetPageClassName();

            Assert.AreEqual("Events.SliderAndButton", pageName);
        }
Ejemplo n.º 2
0
        public void PushNewPage(string xaml)
        {
            var tcs = new TaskCompletionSource <bool>();

            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    Page page;

                    var discovery  = new XamlDocumentDiscovery(xaml);
                    var xClassName = discovery.GetPageClassName();

                    if (string.IsNullOrWhiteSpace(xClassName))
                    {
                        page       = new ContentPage();
                        var loaded = _xamlLoader.Load(page, xaml, ShowError);
                        if (loaded == null)
                        {
                            return;
                        }
                    }
                    else
                    {
                        var type = _typeFinder.Find(xClassName);
                        if (type == null)
                        {
                            ShowError($"The type {xClassName} was not found. Try loading the project assemblies, first.");
                            return;
                        }

                        try
                        {
                            page = Activator.CreateInstance(type) as Page;
                        }
                        catch (Exception e)
                        {
                            ShowError(e);
                            return;
                        }
                    }

                    await Navigation.PopAsync(false);
                    await Navigation.PushAsync(page, false);

                    App.CurrentDesignSurface = page;
                    SetPageId(page);

                    DesignerAppEvents.SetupDesignSurface(page);
                }
                catch (Exception)
                {
                    ShowError();
                }
                finally
                {
                    tcs.SetResult(true);
                }
            });

            tcs.Task.Wait();
        }