NavigateToString() public method

public NavigateToString ( [ text ) : void
text [
return void
Exemplo n.º 1
0
        public void Print(string html)
        {
            Window.Current.Content = ViewToPrint;
            ViewToPrint.NavigateToString(html);


            if (PrintDoc != null)
            {
                printDoc.GetPreviewPage -= PrintDoc_GetPreviewPage;
                printDoc.Paginate       -= PrintDoc_Paginate;
                printDoc.AddPages       -= PrintDoc_AddPages;
            }

            printDoc = new PrintDocument();

            try
            {
                printDoc.GetPreviewPage += PrintDoc_GetPreviewPage;
                printDoc.Paginate       += PrintDoc_Paginate;
                printDoc.AddPages       += PrintDoc_AddPages;

                var showprint = PrintManager.ShowPrintUIAsync();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            PrintDoc = null;
            GC.Collect();
        }
Exemplo n.º 2
0
#pragma warning disable CS1998
        /// <summary>
        /// Converts HTML to PNG
        /// </summary>
        /// <param name="html">HTML.</param>
        /// <param name="fileName">File name.</param>
        /// <param name="onComplete">On complete.</param>
        public async void ToPng(string html, string fileName, Action <string> onComplete)
        {
            var rootPageRenderer = (Xamarin.Forms.Platform.UWP.PageRenderer)Platform.GetRenderer(Forms9Patch.RootPage._instance);

            var size    = new Size(8.5, 11);
            var webView = new Windows.UI.Xaml.Controls.WebView
            {
                DefaultBackgroundColor = Windows.UI.Colors.White,
                Width  = (size.Width - 0.5) * 72 / 2,
                Height = 10, // (size.Height - 0.5) * 72,
            };

            /*
             * var transform = new TranslateTransform();
             * transform.TransformPoint(new Windows.Foundation.Point(0, 0));
             * webView.RenderTransform = transform;
             */
            rootPageRenderer.Children.Add(webView);
            webView.Visibility = Visibility.Visible;

            webView.SetValue(PngFileNameProperty, fileName);
            webView.SetValue(OnCompleteProperty, onComplete);
            webView.SetValue(HtmlStringProperty, html);

            webView.NavigationCompleted += NavigationCompleteA;
            webView.NavigationFailed    += WebView_NavigationFailed;

            webView.NavigateToString(html);
        }
Exemplo n.º 3
0
        public async Task<string> GetSchedule(string user)
        {
            StringBuilder sb = new StringBuilder();

            try
            {

                UnityDataAccess uda = new UnityDataAccess();

               // string sToken = await uda.GetToken(objUnityData.UnitySvcUser, objUnityData.UnitySvcPwd, user);


                string strDate = DateTime.Now.ToString(@"MM/dd/yyyy");


                string sJson = await uda.Magic("GetSchedule", objUnityData.UnityAppUser, objUnityData.UnityAppName, "", objUnityData.Token, strDate, "", "", "", "", "", "");
                return sJson;
            }
            catch (Exception ex)
            {
                WebView wc = new WebView();
                wc.NavigateToString(ex.Message);
                Window.Current.Content = wc;
                return ""; 

            }
                
        }
Exemplo n.º 4
0
 private static void OnHTMLTextChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
 {
     Windows.UI.Xaml.Controls.WebView wv = obj as Windows.UI.Xaml.Controls.WebView;
     if (wv != null)
     {
         wv.NavigateToString((string)args.NewValue);
     }
 }
Exemplo n.º 5
0
 void Reload()
 {
     if (View.Url?.Contains(":") == true)
     {
         Result.Navigate(GetUri());
     }
     else
     {
         Result.NavigateToString(View.GetExecutableHtml().OrEmpty());
     }
 }
Exemplo n.º 6
0
        public override async Task Init()
        {
            _webView = new WebView
            {
                Name = "PrintWebView" + (instanceCount++).ToString("D3"),
                DefaultBackgroundColor = Windows.UI.Colors.White,
                Visibility             = Visibility.Visible,
            };
            RootPanel.Children.Insert(0, _webView);
            PrintContent = _webView;
            _webView.NavigationCompleted += _webView_NavigationCompleted;;

            if (_sourceWebView != null)
            {
                var contentSize = await _sourceWebView.WebViewContentSizeAsync();

                _webView.Width  = contentSize.Width;
                _webView.Height = contentSize.Height;
                Html            = await _sourceWebView.GetHtml();

                _webView.NavigateToString(Html);
            }
            else if (!string.IsNullOrWhiteSpace(Html))
            {
                _webView.Width  = 96 * 8;
                _webView.Height = 96 * 10.5;
                var    baseTag = $"<base href=\"{BaseUrl}\"></base>";
                string htmlWithBaseTag;
                var    internalWebView = new Windows.UI.Xaml.Controls.WebView();
                internalWebView.NavigationCompleted += async(sender, args) =>
                {
                    var script = BaseInsertionScript.Replace("baseTag", baseTag);
                    await sender.InvokeScriptAsync("eval", new[] { script });

                    htmlWithBaseTag = await sender.InvokeScriptAsync("eval", new[] { "document.documentElement.outerHTML;" });

                    _webView.NavigateToString(!string.IsNullOrEmpty(htmlWithBaseTag) ? htmlWithBaseTag : Html);
                };
                internalWebView.NavigateToString(Html);
            }
            else if (!string.IsNullOrWhiteSpace(Url))
            {
                _webView.Width  = 96 * 8;
                _webView.Height = 96 * 10.5;
                Uri uri = new Uri(Url, UriKind.RelativeOrAbsolute);
                if (!uri.IsAbsoluteUri)
                {
                    uri = new Uri(LocalScheme + Url, UriKind.RelativeOrAbsolute);
                }
                _webView.Source = uri;
            }
        }
Exemplo n.º 7
0
        private async void NavigationCompleteA(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args)
        {
            var contentSize = await webView.WebViewContentSizeAsync();

            webView.NavigationCompleted -= NavigationCompleteA;

            System.Diagnostics.Debug.WriteLine("A contentSize=[" + contentSize + "]");
            System.Diagnostics.Debug.WriteLine("A webView.Size=[" + webView.Width + "," + webView.Height + "]");

            webView.Width  = contentSize.Width;
            webView.Height = contentSize.Height;
            webView.UpdateLayout();

            webView.NavigationCompleted += NavigationCompleteB;

            var html = (string)webView.GetValue(HtmlStringProperty);

            webView.NavigateToString(html);
        }
Exemplo n.º 8
0
        public async Task<string> GetSchedule(string user)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                string strDate = DateTime.Now.ToString(@"MM/dd/yyyy");


                string sJson = await UnityDataService.Magic(UnityDataAccessActions.GetSchedule, UnityDataService.UnityAppUser, UnityDataService.UnityAppName, "", UnityDataService.Token, strDate, "", "", "", "", "", "");
                return sJson;
            }
            catch (Exception ex)
            {
                WebView wc = new WebView();
                wc.NavigateToString(ex.Message);
                Window.Current.Content = wc;
                return "";
            }
        }
Exemplo n.º 9
0
        private static Task<string> GetUserAgent()
        {
            var tcs = new TaskCompletionSource<string>();

            WebView webView = new WebView();

            string htmlFragment =
              @"<html>
                    <head>
                        <script type='text/javascript'>
                            function GetUserAgent() 
                            {
                                return navigator.userAgent;
                            }
                        </script>
                    </head>
                </html>";

            webView.NavigationCompleted += async (sender, e) =>
            {
                try
                {
                    //Invoke the javascript when the html load is complete
                    string result = await webView.InvokeScriptAsync("GetUserAgent", null);

                    //Set the task result
                    tcs.TrySetResult(result);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            };

            //Load Html
            webView.NavigateToString(htmlFragment);

            return tcs.Task;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Установить агент.
        /// </summary>
        /// <returns>Агент.</returns>
        public async Task SetDefaultBrowserAgent()
        {
            var tcs = new TaskCompletionSource<string>(TaskCreationOptions.None);
            var ww = new WebView();
            ww.NavigateToString(@"<html>
    <head>
        <script type='text/javascript'>
            function getUserAgent() 
            { 
                return navigator.userAgent; 
            }
        </script>
    </head>
    <body>
    </body>
</html>");
            ww.NavigationCompleted += async (sender1, e1) =>
            {
                try
                {
                    var ua = await ww.InvokeScriptAsync("getUserAgent", new string[0]);
                    tcs.TrySetResult(ua);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            };
            var task = tcs.Task;
            var tua = await task;
            BrowserUserAgent = tua;
        }
Exemplo n.º 11
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="wv"></param>
 public ChatBoxTool(WebView wv)
 {
     _chat_box = wv;
     _chat_box.NavigateToString(_bastChatHtml);          
 }
Exemplo n.º 12
0
 public static void SetHtml(WebView webView, string html)
 {
     webView.NavigateToString(html);
 }
Exemplo n.º 13
0
 private void GetUserAgent()
 {
     // Only get user agent if running on UI thread
     if (CoreWindow.GetForCurrentThread() != null)
     {
         var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
         dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
         {
             // Create a new WebView and get user agent
             WebView wv = new WebView();
             wv.Visibility = Visibility.Collapsed;
             wv.ScriptNotify += new NotifyEventHandler(UserAgentScriptNotify);
             string html =
                 "<html><head><script type='text/javascript'>function GetUserAgent() {" +
                 "window.external.notify(navigator.userAgent);}" +
                 "</script></head>" +
                 "<body onload='GetUserAgent();'></body></html>";
             wv.NavigateToString(html);
         });
     }
 }
        private void LoadWebContent(WebView browser, Item selectedItem)
        {
            #if WINDOWS_APP
            if (AppSettings.MaximizeYoutubeVideos)
            {
                var youtubeLink = Regex.Match(selectedItem.Description, @"(https?:)?//w*\.?youtube.com/watch[^'\""<>]+").Value;

                if (youtubeLink.Length > 0)
                {
                    //Youtube videos get full screen
                    browser.Navigate(new Uri(youtubeLink));
                    return;
                }
            }
            #endif

            var bc = AppSettings.BackgroundColorOfDescription[0] == '#' ? AppSettings.BackgroundColorOfDescription : FetchBackgroundColor();

            var fc = AppSettings.FontColorOfDescription[0] == '#' ? AppSettings.FontColorOfDescription : FetchFontColor();

            string scriptOptions = string.Empty;
            string disableHyperLinksJS = "<script type='text/javascript'>window.onload = function() {   var anchors = document.getElementsByTagName(\"a\"); for (var i = 0; i < anchors.length; i++) { anchors[i].onclick = function() {return(false);}; }};</script>";
            string disableOpeningHyperLinksInNewTabJS = "<script type='text/javascript'>window.onload = function() {   var anchors = document.getElementsByTagName(\"a\"); for (var i = 0; i < anchors.length; i++) { anchors[i].target = \"_self\"; }};</script>";
            string launchPhoneCallJS = @"<script type='text/javascript'>  function callOutToCSharp(stringParameter){window.external.notify(stringParameter.toLocaleString());} window.onload = function() {   var regex = /((\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4})/, replacement = '<input type=""button"" value=""$1"" onclick=""callOutToCSharp(\'launchPhoneCall:$1\');"" />'; function replaceText(el) { if (el.nodeType === 3) { if (regex.test(el.data)) { var temp_div = document.createElement('div'); temp_div.innerHTML = el.data.replace(regex, replacement); var nodes = temp_div.childNodes; while (nodes[0]) { el.parentNode.insertBefore(nodes[0],el); } el.parentNode.removeChild(el); } } else if (el.nodeType === 1) { for (var i = 0; i < el.childNodes.length; i++) { replaceText(el.childNodes[i]);  }  }} replaceText(document.body); } </script>";

            if (AppSettings.DisableHyperLinksInItemDescriptionView)
                scriptOptions = scriptOptions + disableHyperLinksJS;
            if (AppSettings.DisableOpeningHyperLinksInNewTab)
                scriptOptions = scriptOptions + disableOpeningHyperLinksInNewTabJS;
            #if WINDOWS_PHONE_APP
            if (AppSettings.EnableParsingPhoneNumbersPhone8X)
                scriptOptions = scriptOptions + launchPhoneCallJS;
            #endif

            var webcontent = "<!doctype html><HTML>" +
            "<HEAD>" +
            "<meta name=\"viewport\" content=\"width=320, user-scrollable=no\" />"
            +
                scriptOptions
            +
            "<style type='text/css'>a img {border: 0;}</style>" +
            "</HEAD>" +
            "<BODY style=\"background-color:" + bc + ";color:" + fc + ";-ms-touch-action: pan-y;" + "\">" +
            selectedItem.Description +
            "</BODY>" +
            "</HTML>";

            browser.NavigateToString(webcontent);
        }