/// <summary>
		/// Creates the binding context.
		/// </summary>
		void CreateBindingContext ()
		{
			var viewModel = new ComicBooksViewModel ();
			var menuItems = new List<MenuOption> ();
			foreach (var item in viewModel.ComicBooks.OrderBy(x => x.SeriesNumber)) {
				menuItems.Add (new MenuOption{ 
					Order = item.SeriesNumber, 
					ImageUrl = item.ImageSmall,
					MenuOptionTitle = item.ListName
				});
			}

			menuItems.Add (new MenuOption{ 
				Order = 99, 
				ImageUrl = "",
				MenuOptionTitle = "About"
			});

			_menuOptions = menuItems;

			BindingContext = this;

			MenuList.ItemSelected += (sender, e) =>
			{
				var selectedItem = e.SelectedItem as MenuOption;

				if (selectedItem != null){
					if (selectedItem.Order == 10){
						var mappingByHand = new MappingByHand(
							viewModel.ComicBooks.FirstOrDefault(b => b.SeriesNumber == selectedItem.Order));
						Navigation.PushAsync(mappingByHand);
					}

					if (selectedItem.Order == 11){
						var hardworkPage = new CodeBinding(Mapper.Map<ComicBook, ComicBookViewModel>(
							viewModel.ComicBooks.FirstOrDefault(b => b.SeriesNumber == selectedItem.Order)));
						Navigation.PushAsync(hardworkPage);
					}

					if (selectedItem.Order == 12){
						var hardworkPage = new XamlBinding(Mapper.Map<ComicBook, ComicBookViewModel>(
							viewModel.ComicBooks.FirstOrDefault(b => b.SeriesNumber == selectedItem.Order)));
						Navigation.PushAsync(hardworkPage);
					}
					((ListView)sender).SelectedItem = null;
				}
			};
		}
Esempio n. 2
0
		public ListPage ()
		{
			SetValue(Page.TitleProperty, "Comics");

			var viewModel = new ComicBooksViewModel ();

			BackgroundColor = UIHelper.BackgroundColor;

			var list = new ListView();

			list.ItemsSource = viewModel.ComicBooks.OrderBy(x => x.SeriesNumber).ToList();

			Cell = new DataTemplate(typeof(ImageCell));
			Cell.SetBinding(TextCell.TextProperty, "ListName");
			Cell.SetBinding(ImageCell.ImageSourceProperty, "ImageSmall");

			list.ItemTemplate = Cell;

			list.ItemSelected += (sender, e) =>
			{
				var selectedItem = e.SelectedItem as ComicBook;

				if (selectedItem != null){
					if (selectedItem.SeriesNumber == 10){
						var mappingByHand = new MappingByHand(selectedItem);
						Navigation.PushAsync(mappingByHand);
					}

					if (selectedItem.SeriesNumber == 11){
						var hardworkPage = new CodeBinding(Mapper.Map<ComicBook, ComicBookViewModel>(selectedItem));
						Navigation.PushAsync(hardworkPage);
					}

					if (selectedItem.SeriesNumber == 12){
						var hardworkPage = new XamlBinding(Mapper.Map<ComicBook, ComicBookViewModel>(selectedItem));
						Navigation.PushAsync(hardworkPage);
					}
				}
			};

			Content = list;	
		}