public MasterView(MenuViewModel viewModel) { this.BindingContext = viewModel; this.Title = "Title"; var layout = new StackLayout { Spacing = 0 }; var listView = new ListView(); var cell = new DataTemplate(typeof(ImageCell)); cell.SetBinding(TextCell.TextProperty, MenuViewModel.TitlePropertyName); cell.SetBinding(ImageCell.ImageSourceProperty, "Icon"); listView.ItemTemplate = cell; listView.ItemsSource = viewModel.MenuItems; if (about == null) about = new AboutView(); PageSelection = about; listView.ItemSelected += (sender, args) => { var menuItem = listView.SelectedItem as HomeMenuItem; menuType = menuItem.MenuType; switch (menuItem.MenuType) { case MenuType.Home: if (home == null) home = new HomeView(); PageSelection = home; break; case MenuType.About: if (about == null) about = new AboutView(); PageSelection = about; break; case MenuType.Feedback: if (feedback == null) feedback = new FeedbackView(); PageSelection = feedback; break; } }; listView.SelectedItem = viewModel.MenuItems[0]; layout.Children.Add(listView); this.Content = layout; }
public MasterView(MenuViewModel viewModel) { this.BindingContext = viewModel; this.Title = "Title"; var layout = new StackLayout { Spacing = 0 }; var listView = new ListView(); var cell = new DataTemplate(typeof(ImageCell)); cell.SetBinding(TextCell.TextProperty, MenuViewModel.TitlePropertyName); cell.SetBinding(ImageCell.ImageSourceProperty, "Icon"); listView.ItemTemplate = cell; listView.ItemsSource = viewModel.MenuItems; if (about == null) { about = new AboutView(); } PageSelection = about; listView.ItemSelected += (sender, args) => { var menuItem = listView.SelectedItem as HomeMenuItem; menuType = menuItem.MenuType; switch (menuItem.MenuType) { case MenuType.Home: if (home == null) { home = new HomeView(); } PageSelection = home; break; case MenuType.About: if (about == null) { about = new AboutView(); } PageSelection = about; break; case MenuType.Feedback: if (feedback == null) { feedback = new FeedbackView(); } PageSelection = feedback; break; } }; listView.SelectedItem = viewModel.MenuItems[0]; layout.Children.Add(listView); this.Content = layout; }