Exemplo n.º 1
0
 private Page CreateDesignSurface()
 {
     App.CurrentDesignSurface = new DesignSurfacePage(_server);
     DesignerAppEvents.SetupDesignSurface(App.CurrentDesignSurface);
     return(App.CurrentDesignSurface);
 }
Exemplo 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();
        }