private void InternalChangeDetailPage(PageContainer pageContainer, MasterDetailPage masterDetail, object parameter)
        {
            var previousViewModel = GetCurrentViewModel();
            var viewModelType     = pageContainer.ViewModel;
            var page = _resolve.CreatePage(viewModelType.GetType());

            masterDetail.Detail = pageContainer.IsNavigationPage ? new NavigationPage(page) : page;
            pageContainer.ViewModel.InternalInitialize(pageContainer.Parameter);
            pageContainer.ViewModel.OnNavigateFrom(previousViewModel, parameter);
            masterDetail.IsPresented = false;
        }
예제 #2
0
        private async Task InternalNavigateToMasterDetailsAsync(PageContainer master, PageContainer detail, MasterDetailPage masterDetailPage = null, bool hasNavBar = false)
        {
            if (master == null || detail == null)
            {
                throw new ArgumentNullException();
            }
            master.IsNavigationPage = true;
            var masterViewModel = master.ViewModel;
            var masterPage      = _resolve.CreatePage(masterViewModel.GetType());

            if (string.IsNullOrEmpty(masterPage.Title))
            {
                masterPage.Title = "Master Title";
            }
            var detailViewModel = detail.ViewModel;
            var detailPage      = _resolve.CreatePage(detailViewModel.GetType());

            if (masterDetailPage == null)
            {
                masterDetailPage = new MasterDetailPage();
            }
            masterDetailPage.Master = masterPage;
            masterDetailPage.Detail = detail.IsNavigationPage ? new NavigationPage(detailPage) : detailPage;

            var navigation = Application.Current.MainPage;

            if (navigation != null)
            {
                if (hasNavBar)
                {
                    await navigation.Navigation.PushModalAsync(new NavigationPage(masterDetailPage));
                }
                else
                {
                    await navigation.Navigation.PushModalAsync(masterDetailPage);
                }
            }
            else
            {
                Application.Current.MainPage = masterDetailPage;
            }
            masterViewModel.Initialize(master.Parameter);
            detailViewModel.Initialize(detail.Parameter);
        }
예제 #3
0
        /// <summary>
        /// method to add tabbed page in run time take one parameter page container
        /// </summary>
        /// <param name="pageContainer"></param>
        /// <returns>boolean whatever the page added successfully or not</returns>
        public bool AddPageToTabbedPage(PageContainer pageContainer)
        {
            try
            {
                if (Application.Current.MainPage == null)
                {
                    return(false);
                }

                var modalStack      = Application.Current.MainPage.Navigation.ModalStack;
                var navigationStack = Application.Current.MainPage.Navigation.NavigationStack;

                var currentTabbedPage = Application.Current.MainPage;
                if (currentTabbedPage is TabbedPage baseTabbedPage)
                {
                    InternalAddPageToTabbedPage(pageContainer, baseTabbedPage);
                    return(true);
                }

                currentTabbedPage = modalStack.FirstOrDefault(x => x.GetType() == typeof(TabbedPage));
                if (currentTabbedPage is TabbedPage modalTabbedPage)
                {
                    InternalAddPageToTabbedPage(pageContainer, modalTabbedPage);
                    return(true);
                }

                currentTabbedPage = navigationStack.FirstOrDefault(x => x.GetType() == typeof(TabbedPage));
                if (currentTabbedPage is TabbedPage tabbedPageInNavigation)
                {
                    InternalAddPageToTabbedPage(pageContainer, tabbedPageInNavigation);
                    return(true);
                }
                return(false);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(false);
            }

            Console.WriteLine("there is not any tabbed page in navigation stack");
            return(false);
        }
예제 #4
0
        /// <summary>
        /// method to change details page with another on take one parameter page container
        /// </summary>
        /// <param name="pageContainer"></param>
        /// <returns></returns>
        public bool ChangeDetailPage(PageContainer pageContainer)
        {
            try
            {
                if (Application.Current.MainPage == null)
                {
                    return(false);
                }

                var modalStack      = Application.Current.MainPage.Navigation.ModalStack;
                var navigationStack = Application.Current.MainPage.Navigation.NavigationStack;

                var currentMasterDetailPage = Application.Current.MainPage;
                if (currentMasterDetailPage is MasterDetailPage baseMasterDetail)
                {
                    InternalChangeDetailPage(pageContainer, baseMasterDetail);
                    return(true);
                }

                currentMasterDetailPage = modalStack.FirstOrDefault(x => x.GetType() == typeof(MasterDetailPage));
                if (currentMasterDetailPage is MasterDetailPage modalMasterDetail)
                {
                    InternalChangeDetailPage(pageContainer, modalMasterDetail);
                    return(true);
                }

                currentMasterDetailPage = navigationStack.FirstOrDefault(x => x.GetType() == typeof(MasterDetailPage));
                if (currentMasterDetailPage is MasterDetailPage masterDetailInNavigation)
                {
                    InternalChangeDetailPage(pageContainer, masterDetailInNavigation);
                    return(true);
                }
                return(false);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(false);
            }
        }
예제 #5
0
 /// <summary>
 /// async method to navigate to master detail page with master and detail page as parameter also if you want to keep navigation bar or not as optional parameter also if you want to use custom master detail page
 /// </summary>
 /// <param name="master"></param>
 /// <param name="detail"></param>
 /// <param name="masterDetailPage"></param>
 /// <param name="hasNavBar"></param>
 /// <returns></returns>
 public Task NavigateToMasterDetailsAsync(PageContainer master, PageContainer detail, MasterDetailPage masterDetailPage = null,
                                          bool hasNavBar = false)
 {
     return(InternalNavigateToMasterDetailsAsync(master, detail, masterDetailPage, hasNavBar));
 }