예제 #1
0
        /// <summary>
        /// Set MainPage to a Master Detail page container.
        /// Also initializes all viewmodels.
        /// </summary>
        /// <typeparam name="TPage">Must be of type TabbedPage.</typeparam>
        /// <returns></returns>
        public static async Task SetMasterDetailPage <TMasterPage, TDetailPage>(int pageIndex = 0,
                                                                                YamvvmViewModel masterDetailViewModel = null,
                                                                                PageViewModel masterViewModel         = null,
                                                                                PageViewModel detailViewModel         = null)
            where TMasterPage : YamvvmPage, new()
            where TDetailPage : YamvvmPage, new()
        {
            MasterDetailPage masterDetailPage = new MasterDetailPage();
            TMasterPage      masterPage       = new TMasterPage();
            TDetailPage      detailsPage      = new TDetailPage();

            masterDetailPage.Master = masterPage;
            masterDetailPage.Detail = new NavigationPage(detailsPage);

            var initTasks = new List <Task>();

            if (masterDetailViewModel != null)
            {
                masterDetailPage.BindingContext = masterDetailViewModel;
                initTasks.Add(masterDetailViewModel.Initialise());
            }

            if (masterViewModel != null)
            {
                masterPage.BindingContext = masterViewModel;
                initTasks.Add(masterViewModel.Initialise());
            }

            if (detailViewModel != null)
            {
                detailsPage.BindingContext = detailViewModel;
                initTasks.Add(detailViewModel.Initialise());
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                Application.Current.MainPage = masterDetailPage;
            });

            await CleanupPreviousMainPage();

            await Task.WhenAll(initTasks);
        }