Пример #1
0
        /// <summary>
        /// Registers a Page for navigation based on the Device Idiom using a shared ViewModel
        /// </summary>
        /// <typeparam name="TView">Default View Type to be used across multiple Idioms if they are not specified directly.</typeparam>
        /// <typeparam name="TViewModel">The shared ViewModel</typeparam>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="name">The common name used for Navigation. If left empty or null will default to the ViewModel root name. i.e. MyPageViewModel => MyPage</param>
        /// <param name="desktopView">Desktop Specific View Type</param>
        /// <param name="tabletView">Tablet Specific View Type</param>
        /// <param name="phoneView">Phone Specific View Type</param>
        public static void RegisterForNavigationOnIdiom <TView, TViewModel>(this ICodeBrixContainer container, string name = null, Type desktopView = null, Type tabletView = null, Type phoneView = null)
            where TView : Page
            where TViewModel : class
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = typeof(TView).Name;
            }

            if (Device.Idiom == TargetIdiom.Desktop && desktopView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(desktopView, name);
            }
            else if (Device.Idiom == TargetIdiom.Phone && phoneView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(phoneView, name);
            }
            else if (Device.Idiom == TargetIdiom.Tablet && tabletView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(tabletView, name);
            }
            else
            {
                container.RegisterForNavigation <TView, TViewModel>(name);
            }
        }
Пример #2
0
        // ReSharper disable InconsistentNaming

        /// <summary>
        /// Registers a Page for navigation based on the current Device OS using a shared ViewModel
        /// </summary>
        /// <typeparam name="TView">Default View Type to be shared across multiple Device Operating Systems if they are not specified directly.</typeparam>
        /// <typeparam name="TViewModel">Shared ViewModel Type</typeparam>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="name">The unique name to register with the Page. If left empty or null will default to the ViewModel root name. i.e. MyPageViewModel => MyPage</param>
        /// <param name="androidView">Android Specific View Type</param>
        /// <param name="iOSView">iOS Specific View Type</param>
        /// <param name="UWPView">Windows Universal (UWP) Specific View Type</param>
        /// <param name="macOSView">macOS Specific View Type</param>
        /// <param name="otherView">Other Platform Specific View Type</param>
        public static void RegisterForNavigationOnPlatform <TView, TViewModel>(this ICodeBrixContainer container, string name = null, Type androidView = null, Type iOSView = null, Type UWPView = null, Type macOSView = null, Type otherView = null)
            where TView : Page
            where TViewModel : class
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = typeof(TView).Name;
            }

            if (Device.RuntimePlatform == Device.Android && androidView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(androidView, name);
            }
            else if (Device.RuntimePlatform == Device.iOS && iOSView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(iOSView, name);
            }
            else if (Device.RuntimePlatform == Device.UWP && UWPView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(UWPView, name);
            }
            else if (Device.RuntimePlatform == Device.macOS && macOSView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(macOSView, name);
            }
            else if (otherView != null)
            {
                container.RegisterForNavigationWithViewModel <TViewModel>(otherView, name);
            }
            else
            {
                container.RegisterForNavigation <TView, TViewModel>(name);
            }
        }
Пример #3
0
        /// <summary>
        /// Registers a Page for navigation based on the current Device OS using a shared ViewModel
        /// </summary>
        /// <typeparam name="TView">Default View Type to be shared across multiple Device Operating Systems if they are not specified directly.</typeparam>
        /// <typeparam name="TViewModel">Shared ViewModel Type</typeparam>
        /// <param name="container"><see cref="ICodeBrixContainer"/> used to register type for Navigation.</param>
        /// <param name="name">The unique name to register with the Page. If left empty or null will default to the View name.</param>
        /// <param name="platforms"></param>
        public static void RegisterForNavigationOnPlatform <TView, TViewModel>(this ICodeBrixContainer container, string name, params Prism.IPlatform[] platforms)
            where TView : Page
            where TViewModel : class
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = typeof(TView).Name;
            }

            foreach (var platform in platforms)
            {
                if (Device.RuntimePlatform == platform.RuntimePlatform.ToString())
                {
                    container.RegisterForNavigationWithViewModel <TViewModel>(platform.ViewType, name);
                }
            }

            container.RegisterForNavigation <TView, TViewModel>(name);
        }
Пример #4
0
 /// <summary>
 /// Registers a Page for navigation.
 /// </summary>
 /// <typeparam name="TView">The Type of Page to register</typeparam>
 /// <typeparam name="TViewModel">The ViewModel to use as the BindingContext for the Page</typeparam>
 /// <param name="name">The unique name to register with the Page</param>
 /// <param name="container"></param>
 public static void RegisterForNavigation <TView, TViewModel>(this ICodeBrixContainer container, string name = null)
     where TView : Page
     where TViewModel : class
 {
     container.RegisterForNavigationWithViewModel <TViewModel>(typeof(TView), name);
 }