Пример #1
0
        /// <summary>
        /// Handles the Uri for the following types:
        /// - Web url
        /// - Email
        /// - Telephone
        /// - SMS
        /// - GEO
        /// </summary>
        /// <param name="label"></param>
        /// <param name="url"></param>
        /// <returns>true if the uri has been handled correctly, false if the uri is not handled because of an error</returns>
        public static bool HandleUriClick(HtmlLabel label, string url)
        {
            if (url == null || !Uri.IsWellFormedUriString(WebUtility.UrlEncode(url), UriKind.RelativeOrAbsolute))
            {
                return(false);
            }

            var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource {
                Url = url
            }, url);

            label.SendNavigating(args);

            if (args.Cancel)
            {
                // Uri is handled because it is cancled;
                return(true);
            }
            bool result = false;
            var  uri    = new Uri(url);

            if (uri.IsHttp())
            {
                uri.LaunchBrowser(label.BrowserLaunchOptions);
                result = true;
            }
            else if (uri.IsEmail())
            {
                result = uri.LaunchEmail();
            }
            else if (uri.IsTel())
            {
                result = uri.LaunchTel();
            }
            else if (uri.IsSms())
            {
                result = uri.LaunchSms();
            }
            else if (uri.IsGeo())
            {
                result = uri.LaunchMaps();
            }
            else
            {
                result = Launcher.TryOpenAsync(uri).Result;
            }
            // KWI-FIX What to do if the navigation failed? I assume not to spawn the SendNavigated event or introduce a fail bit on the args
            label.SendNavigated(args);
            return(result);
        }
Пример #2
0
        public static void HandleUriClick(HtmlLabel label, string url)
        {
            if (url == null || !Uri.IsWellFormedUriString(WebUtility.UrlEncode(url), UriKind.RelativeOrAbsolute))
            {
                return;
            }

            var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource {
                Url = url
            }, url);

            label.SendNavigating(args);

            if (args.Cancel)
            {
                return;
            }

            var uri = new Uri(url);

            if (uri.IsHttp())
            {
                uri.LaunchBrowser(label.BrowserLaunchOptions);
            }
            else if (uri.IsEmail())
            {
                uri.LaunchEmail();
            }
            else if (uri.IsTel())
            {
                uri.LaunchTel();
            }
            else if (uri.IsSms())
            {
                uri.LaunchSms();
            }
            else if (uri.IsGeo())
            {
                uri.LaunchMaps();
            }
            else
            {
                Launcher.TryOpenAsync(url);
            }

            label.SendNavigated(args);
        }