示例#1
0
        /// <summary>
        /// Initializes the main UI view navigation system and navigates to the specified view model view.
        /// </summary>
        /// <typeparam name="TViewModel">The type of view model to register.</typeparam>
        /// <param name="mainThreadScheduler">The scheduler which schedules tasks on the main UI thread.</param>
        /// <param name="backgroundScheduler">The scheduler which schedules tasks in the background.</param>
        /// <param name="viewLocator">A view locator which is responsible for finding a view for a view model pair.</param>
        /// <returns>The navigation view.</returns>
        public static NavigationView Initialize <TViewModel>(IScheduler mainThreadScheduler = null, IScheduler backgroundScheduler = null, IViewLocator viewLocator = null)
            where TViewModel : class, IPageViewModel
        {
            var bgScheduler = mainThreadScheduler ?? RxApp.TaskpoolScheduler;
            var mScheduler  = backgroundScheduler ?? RxApp.MainThreadScheduler;
            var vLocator    = viewLocator ?? Locator.Current.GetService <IViewLocator>();

            var navigationView   = new NavigationView(mScheduler, bgScheduler, vLocator);
            var viewStackService = new ViewStackService(navigationView);

            Locator.CurrentMutable.Register <IViewStackService>(() => viewStackService);
            navigationView.PushPage(Activator.CreateInstance(typeof(TViewModel), viewStackService) as TViewModel, null, true, false).Subscribe();

            return(navigationView);
        }
示例#2
0
        public static IMutableDependencyResolver RegisterNavigationView <TView>(this IMutableDependencyResolver dependencyResolver, Func <TView> navigationViewFactory)
            where TView : IView
        {
            if (dependencyResolver is null)
            {
                throw new ArgumentNullException(nameof(dependencyResolver));
            }

            if (navigationViewFactory is null)
            {
                throw new ArgumentNullException(nameof(navigationViewFactory));
            }

            var navigationView   = navigationViewFactory();
            var viewStackService = new ViewStackService(navigationView);

            dependencyResolver.RegisterLazySingleton <IViewStackService>(() => viewStackService);
            dependencyResolver.RegisterLazySingleton <IView>(() => navigationView, NavigationView);
            return(dependencyResolver);
        }