using System; using TINK.View.Info.BikeInfo; #if USEMASTERDETAIL || USEFLYOUT using TINK.View.MasterDetail; #endif using TINK.ViewModel.MasterDetail; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace TINK.View { /// /// Delegate to perform navigation. /// public delegate void ShowPageDelegate(Type p_oType, string p_strTitle = null); [XamlCompilation(XamlCompilationOptions.Compile)] #if USEMASTERDETAIL || USEFLYOUT public partial class MainPage : MasterDetailPage, INavigationMasterDetail #else public partial class MainPage : MasterDetailPage #endif { public MainPage() { InitializeComponent(); MasterPage.ShowPageViewService = ShowPage; // Any type of split behaviour conflics with map shifting functionality. MasterBehavior = MasterBehavior.Popover; var navigationPage = Detail as NavigationPage; if (navigationPage == null) { return; } #if USEMASTERDETAIL || USEFLYOUT var detailPage = navigationPage.RootPage as IDetailPage; if (detailPage == null) { return; } detailPage.NavigationMasterDetail = this; #endif } /// Creates and a page an shows it. /// Type of page to show. public void ShowPage( Type p_oTypeOfPage, string p_strTitle = null) { if (p_oTypeOfPage == null) return; var page = (Page)Activator.CreateInstance(p_oTypeOfPage); page.Title = p_strTitle ?? Helper.GetCaption(p_oTypeOfPage); #if USEMASTERDETAIL || USEFLYOUT var l_oPage = page as IDetailPage; if (l_oPage != null) { l_oPage.NavigationMasterDetail = this; } #endif #if !BACKSTYLE // When bike info page is shown do not allow to close this carousel before all pages were displayed. IsGestureEnabled = p_oTypeOfPage != typeof(BikeInfoCarouselPage); Detail = new NavigationPage(page); IsPresented = false; #else Detail.Navigation.PushAsync(page); IsPresented = false; while (Detail.Navigation.NavigationStack.Count > 2) { // Ensure that stack does never contains more than 2 pages (root page + one child) // This can occure if from child via swipe onther child is opened. // Remove item after adding new one to avoid flickering. Detail.Navigation.RemovePage(Detail.Navigation.NavigationStack[1]); } #endif MasterPage.ListView.SelectedItem = null; } } }