Пример #1
0
        /// <summary>
        /// Registers a Page for navigation
        /// </summary>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="viewType">The type of Page to register</param>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterForNavigation(this ICodeBrixContainer container, Type viewType, string name)
        {
            if (viewType == typeof(Xamarin.Forms.NavigationPage) && name == "NavigationPage")
            {
                throw new InvalidOperationException("It is not necessary to register the 'Xamarin.Forms.NavigationPage' type (unless you are "
                                                    + "registering it with a specific ViewFactory) - this type is automatically registered.");
            }

            PageNavigationRegistry.Register(name, viewType);
            RegisteredPages.Add(name);
            //Was: container.Register(typeof(object), viewType, name); //Not sure why it wanted to register types as 'Object'
            container.Register(viewType, viewType, name);
        }
Пример #2
0
        /// <summary>
        /// Registers a Page for navigation, with a function to create the Page during resolution
        /// </summary>
        /// <typeparam name="TView">The Type of Page to register</typeparam>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="viewFactory">A function that will create an instance of the view type</param>
        /// <param name="name">The unique name to register with the Page</param>
        public static void RegisterForNavigation <TView>(this ICodeBrixContainer container, Func <TView> viewFactory, string name = null) where TView : Page
        {
            if (viewFactory == null)
            {
                throw new ArgumentNullException(nameof(viewFactory));
            }
            var viewType = typeof(TView);

            if (string.IsNullOrWhiteSpace(name))
            {
                name = viewType.Name;
            }

            PageNavigationRegistry.Register(name, viewType);
            RegisteredPages.Add(name);
            // ReSharper disable once RedundantTypeArgumentsOfMethod
            container.Register <TView>(viewFactory, name);
        }