Exemplo n.º 1
0
        public WebViewPage(IWebEntrance entrance)
        {
            InitializeComponent();
            ShowIsBusyDialog = true;
            var meta = entrance.GetType().GetCustomAttribute(typeof(EntAttr)) as EntAttr;

            Title = meta.Title;

            InfoEntrance = entrance;
            var baseController = InfoEntrance as BaseController;

            ViewModel = baseController;

            if (entrance is IInfoEntrance ie)
            {
                var sb = new StringBuilder();
                ie.HtmlDocument.ToHtml(sb);
                WebView.Html = sb.ToString();
            }
            else if (entrance is IUrlEntrance iu)
            {
                WebView.Uri              = iu.HtmlUrl;
                WebView.Cookie           = iu.Cookie;
                WebView.OpenWithPost     = iu.OpenWithPost;
                WebView.SubUrlRequested += OnSubUrlRequested;

                if (WebView.Uri.Contains("://"))
                {
                    baseController.SetIsBusy(true);
                    WebView.LoadCompleted += () => baseController.SetIsBusy(false);
                }
            }

            foreach (var key in InfoEntrance.Menu)
            {
                ToolbarItems.Add(new ToolbarItem
                {
                    Text             = key.Name,
                    Command          = key.Command,
                    CommandParameter = (Action <IWebEntrance>)OnEntranceRequested
                });
            }

            entrance.Evaluate = WebView.JavaScript;
            WebView.RegisterAction(entrance.Receive);
        }
Exemplo n.º 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            System.Diagnostics.Debug.Assert(e.Parameter is IWebEntrance, "Error leading");
            InfoEntrance = e.Parameter as BaseController;

            var meta = InfoEntrance.GetType().GetCustomAttribute(typeof(EntAttr)) as EntAttr;

            ViewModel             = e.Parameter as BaseController;
            ViewModel.Title       = meta.Title;
            InfoEntrance.Evaluate = WebView.InvokeScript;
            InfoEntrance.View     = ViewResponse;

            WebView.Register = InfoEntrance.Receive;
            foreach (var key in InfoEntrance.Menu)
            {
                PrimaryMenu.Add(new AppBarButton
                {
                    Label            = key.Name,
                    Command          = key.Command,
                    CommandParameter = (Action <IWebEntrance>)OnEntranceRequested,
                    Icon             = new FontIcon
                    {
                        FontFamily = new FontFamily("Segoe MDL2 Assets"),
                        Glyph      = key.Icon
                    }
                });
            }

            if (InfoEntrance is IInfoEntrance info)
            {
                var sb = new StringBuilder();
                info.HtmlDocument.ToHtml(sb);
                WebView.Html = sb.ToString();
            }
            else if (InfoEntrance is IUrlEntrance urle)
            {
                WebView.Url              = urle.HtmlUrl;
                WebView.SubUrlRequested += OnSubUrlRequested;

                if (WebView.Url.Contains("://"))
                {
                    ViewModel.SetIsBusy(true);
                    WebView.LoadCompleted += () => ViewModel.SetIsBusy(false);
                }
            }
        }
Exemplo n.º 3
0
 protected virtual void OnEntranceRequested(IWebEntrance ent)
 {
     new WebViewPage(ent).ShowAsync(Navigation);
 }
Exemplo n.º 4
0
 private void OnEntranceRequested(IWebEntrance entrance)
 {
     Frame.Navigate(typeof(WebViewPage), entrance);
 }