protected override bool OnBackButtonPressed() { if (mode == GalleryMode.Selection) { foreach (var img in selectedItems) { img.IsSelected = false; } selectedItems.Clear(); mode = GalleryMode.Normal; MakeOptionsVisible(); UpdateTitle(); return(true); } return(false); }
public GalleryPage() { NavigationPage.SetHasNavigationBar(this, false); InitializeComponent(); selectedItems = new List <ImageDisplay>(); mode = GalleryMode.Normal; //Title = "Gallery"; deleteOption = new ToolbarItem("Delete", "", new Action(() => { DeleteSelectedImage(); }), ToolbarItemOrder.Primary, 0); view = new StackLayout(); scrollView = new ScrollView { Orientation = ScrollOrientation.Vertical }; Update(); this.InitialLoad(); }
private void SetView() { view.Children.Clear(); foreach (var i in foodDiary) { DateTime date = i.Key; List <FoodItem> foods = i.Value; Label dateLabel = new Label { Text = date.ToLongDateString(), TextColor = Color.Gray, FontSize = 15, HorizontalOptions = LayoutOptions.StartAndExpand, Margin = new Thickness(5, 10, 0, 0) }; Grid imageGrid = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(App.ScreenWidth / 4, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(App.ScreenWidth / 4, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(App.ScreenWidth / 4, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(App.ScreenWidth / 4, GridUnitType.Absolute) } }, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start }; List <ImageDisplay> images = new List <ImageDisplay>(); foreach (var food in foods) { byte[] thumbnail = DeserializeStringToByteArray(food.IMGBYTES); if (thumbnail != null) { ImageDisplay bmp = new ImageDisplay { ImageByte = thumbnail, BackgroundColor = Color.White, WidthRequest = App.ScreenWidth / 4, HeightRequest = App.ScreenWidth / 4, Margin = new Thickness(0, 0, 0, 0), Aspect = Aspect.AspectFill, DatabaseItem = food }; bmp.OnTouch = new Command((p) => { Console.WriteLine("LongClick"); if (mode == SelfControl.Helpers.GlobalVariables.GalleryMode.Normal) { mode = SelfControl.Helpers.GlobalVariables.GalleryMode.Selection; MakeOptionsVisible(); } bmp.IsSelected = !bmp.IsSelected; if (bmp.IsSelected) { selectedItems.Add(bmp); UpdateTitle(); } else { selectedItems.Remove(bmp); UpdateTitle(); } }); bmp.OnClick = new Command((p) => { if (mode == SelfControl.Helpers.GlobalVariables.GalleryMode.Selection) { bmp.IsSelected = !bmp.IsSelected; if (bmp.IsSelected) { selectedItems.Add(bmp); UpdateTitle(); } else { selectedItems.Remove(bmp); UpdateTitle(); } } else { NagivateImageViewer(bmp.DatabaseItem); } }); images.Add(bmp); } } fillGrid(imageGrid, images); view.Children.Add(dateLabel); view.Children.Add(imageGrid); } var reviewButton = new Button { Text = "Review Your Meals", BorderWidth = 1, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }; reviewButton.Clicked += OnReviewButtonClicked; view.Children.Add(reviewButton); }