void ConfigureTabbedPage(TabbedPage tabbedPage, string segment) { foreach (var child in tabbedPage.Children) { PageUtilitiesExtended.SetAutowireViewModelOnPage(child); _pageBehaviorFactory.ApplyPageBehaviors(child); if (child is NavigationPage navPage) { PageUtilitiesExtended.SetAutowireViewModelOnPage(navPage.CurrentPage); _pageBehaviorFactory.ApplyPageBehaviors(navPage.CurrentPage); } } var parameters = UriParsingHelper.GetSegmentParameters(segment); var tabsToCreate = parameters.GetValues <string>(KnownNavigationParameters.CreateTab); if (tabsToCreate.Count() > 0) { foreach (var tabToCreate in tabsToCreate) { //created tab can be a single view or a view nested in a NavigationPage with the syntax "NavigationPage|ViewToCreate" var tabSegements = tabToCreate.Split('|'); if (tabSegements.Length > 1) { var navigationPage = CreatePageFromSegment(tabSegements[0]) as NavigationPage; if (navigationPage != null) { var navigationPageChild = CreatePageFromSegment(tabSegements[1]); navigationPage.PushAsync(navigationPageChild); //when creating a NavigationPage w/ DI, a blank Page object is injected into the ctor. Let's remove it if (navigationPage.Navigation.NavigationStack.Count > 1) { navigationPage.Navigation.RemovePage(navigationPage.Navigation.NavigationStack[0]); } //set the title because Xamarin doesn't do this for us. navigationPage.Title = navigationPageChild.Title; navigationPage.Icon = navigationPageChild.Icon; tabbedPage.Children.Add(navigationPage); } } else { var tab = CreatePageFromSegment(tabToCreate); tabbedPage.Children.Add(tab); } } } TabbedPageSelectTab(tabbedPage, parameters); }
void ConfigureCarouselPage(CarouselPage carouselPage, string segment) { foreach (var child in carouselPage.Children) { PageUtilitiesExtended.SetAutowireViewModelOnPage(child); } var parameters = UriParsingHelper.GetSegmentParameters(segment); CarouselPageSelectTab(carouselPage, parameters); }
protected virtual Page CreatePageFromSegment(string segment) { try { var segmentName = UriParsingHelper.GetSegmentName(segment); var page = CreatePage(segmentName); if (page == null) { throw new NullReferenceException(string.Format("{0} could not be created. Please make sure you have registered {0} for navigation.", segmentName)); } PageUtilitiesExtended.SetAutowireViewModelOnPage(page); _pageBehaviorFactory.ApplyPageBehaviors(page); ConfigurePages(page, segment); return(page); } catch (Exception e) { _logger.Log(e.ToString(), Category.Exception, Priority.High); throw; } }