Пример #1
0
        /// <summary>
        ///     Checks if the current browser is at the given page
        /// </summary>
        /// <param name="document"></param>
        /// <param name="pageType"></param>
        /// <returns></returns>
        public static bool IsAtPage(this INavigationService document, Type pageType)
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute(pageType);

            if (navigationInfo == null)
            {
                throw new InvalidOperationException("The page type does not specify its uri");
            }

            return(UrlHelpers.MatchUrlPattern(navigationInfo.PageUrl, document.Document.Uri));
        }
        /// <summary>
        ///     Checks if the current browser is at the given page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="document"></param>
        /// <returns></returns>
        public static bool IsAtPage(this INavigationService document, Type pageType)
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute(pageType);

            if (navigationInfo == null)
            {
                throw new InvalidOperationException("The page type does not specify its uri");
            }


            return(UrlHelpers.UrlsAreEqual(ProcessUrlArguments(navigationInfo.Url, null), document.Document.Uri));
        }
        public static void GoTo(this INavigationService document, Assembly containingAssembly, string pageTitle)
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute(containingAssembly, pageTitle);

            if (navigationInfo != null)
            {
                document.GoToPageUrl(ProcessUrlArguments(navigationInfo.Url, new { }));
            }
            else
            {
                throw new InvalidOperationException(
                          "Unable to find page with title " + pageTitle);
            }
        }
        /// <summary>
        ///     Navigates to the given page with the additional URL-string
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="document"></param>
        /// <param name="appendToUrl">Extra string to append to the Page-URL</param>
        /// <returns></returns>
        public static T GoTo <T>(this INavigationService document, string appendToUrl) where T : Page, new()
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute <T>();

            if (navigationInfo != null)
            {
                document.GoToPageUrl(Build(navigationInfo.Url, appendToUrl));
            }
            else
            {
                throw new InvalidOperationException(
                          "You are trying to navigate to a page which does not specify its uri (missing PageDescriptionAttribute)");
            }

            return(document.GetCurrentPage <T>());
        }
        public static T GoTo <T>(this INavigationService document, dynamic arguments) where T : Page, new()
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute <T>();

            if (navigationInfo != null)
            {
                Uri url = ProcessUrlArguments(navigationInfo.Url, arguments);
                document.GoToPageUrl(url);
            }
            else
            {
                throw new InvalidOperationException(
                          "You are trying to navigate to a page which does not specify its uri (missing PageDescriptionAttribute)");
            }

            return(document.GetCurrentPage <T>());
        }
        /// <summary>
        ///     Browses to the given Page with the current browser window
        /// </summary>
        public static object GoTo(this INavigationService document, Type t, dynamic arguments)
        {
            PageDescriptionAttribute navigationInfo = TryGetPageDescriptionAttribute(t);
            Uri url = ProcessUrlArguments(navigationInfo.Url, arguments);

            if (navigationInfo != null)
            {
                document.GoToPageUrl(url);
            }
            else
            {
                throw new InvalidOperationException(
                          "You are trying to navigate to a page which does not specify its uri (missing PageDescriptionAttribute)");
            }
            MethodInfo method        = typeof(NavigationExtensions).GetMethod("GetPage");
            MethodInfo genericMethod = method.MakeGenericMethod(t);

            return(genericMethod.Invoke(null, new object[] { document }));
        }