public HomeView() { pages = new Dictionary<MenuType, NavigationPage> (); BindingContext = new HomeViewModel (); Master = master = new HomeMasterView (ViewModel); var homeNav = new NavigationPage(master.PageSelection) { Tint = Helpers.Color.Greenish.ToFormsColor() }; Detail = homeNav; pages.Add (MenuType.News, homeNav); master.PageSelectionChanged = (menuType) => { NavigationPage newPage; if(pages.ContainsKey(menuType)){ newPage = pages[menuType]; } else{ newPage = new NavigationPage(master.PageSelection){ Tint = Helpers.Color.Greenish.ToFormsColor() }; pages.Add (menuType, newPage); } Detail = newPage; Detail.Title = master.PageSelection.Title; IsPresented = false; }; this.Icon = "slideout.png"; }
public HomeMasterView(HomeViewModel viewModel) { this.Icon = "slideout.png"; BindingContext = viewModel; var layout = new StackLayout { Spacing = 0 }; var label = new ContentView { Padding = new Thickness(10, 36, 0, 5), BackgroundColor = Color.Transparent, Content = new Label { Text = "Menu", Font = Font.SystemFontOfSize (NamedSize.Medium) } }; layout.Children.Add(label); var listView = new ListView (); var cell = new DataTemplate(typeof(ListImageCell)); cell.SetBinding (TextCell.TextProperty, HomeViewModel.TitlePropertyName); cell.SetBinding (ImageCell.ImageSourceProperty, "Icon"); listView.ItemTemplate = cell; listView.ItemsSource = viewModel.MenuItems; if (news == null) news = new NewsView (); PageSelection = about; //Change to the correct page listView.ItemSelected += (sender, args) => { var menuItem = listView.SelectedItem as MenuItem; menuType = menuItem.MenuType; switch(menuItem.MenuType){ case MenuType.About: if(about == null) about = new AboutView(); PageSelection = about; break; case MenuType.Groups: if(groupMatches == null) groupMatches = new GroupMatchView(); PageSelection = groupMatches; break; case MenuType.Knockout: if(knockoutMatches == null) knockoutMatches = new KnockoutMatchView(); PageSelection = knockoutMatches; break; case MenuType.Map: if(map == null) map =new MapView(); PageSelection = map; break; case MenuType.News: if(news == null) news = new NewsView(); PageSelection = news; break; case MenuType.Teams: if(teams == null) teams = new TeamsView(); PageSelection = teams; break; case MenuType.Podcast: if(podcast ==null) podcast = new PodcastView(); PageSelection = podcast; break; } }; listView.SelectedItem = viewModel.MenuItems[0]; layout.Children.Add(listView); Content = layout; }