public ExpenseActionPage(ReportDetailViewModel parentViewModel) { NavigationPage.SetTitleIcon(this, "icon.png"); ViewModel = new ExpenseActionViewModel(parentViewModel); BindingContext = ViewModel; Title = "New Expense"; ViewModel.IsEditable = true; AddConditionalUI(); Content = formLayout; Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0); #region Set Bindings And Event Handlers nameEntry.SetBinding(Entry.TextProperty, "Name"); shortDescriptionEntry.SetBinding(Entry.TextProperty, "ShortDescription"); priceEntry.SetBinding(Entry.TextProperty, "Price", BindingMode.TwoWay, null, "$ {0}"); date.SetBinding(DatePicker.DateProperty, "Date"); saveButton.Clicked += (object sender, EventArgs e) => { ViewModel.Save(); Navigation.PopModalAsync(); }; cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; #endregion }
public ExpenseActionPage(ExpenseModel model, bool editable) { if (model == null) { throw new Exception("Expense model cannot be null"); } NavigationPage.SetTitleIcon(this, "icon.png"); ViewModel = new ExpenseActionViewModel(editable); BindingContext = ViewModel; Title = "New Expense"; if (model != null) { ViewModel.Expense = model; } AddConditionalUI(); Content = formLayout; Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0); #region Set Bindings And Event Handlers nameEntry.SetBinding(Entry.TextProperty, "Name"); shortDescriptionEntry.SetBinding(Entry.TextProperty, "ShortDescription"); priceEntry.SetBinding(Entry.TextProperty, "Price", BindingMode.TwoWay, null, "$ {0}"); date.SetBinding(DatePicker.DateProperty, "Date"); saveButton.Clicked += (object sender, EventArgs e) => { ViewModel.Save(); Navigation.PopModalAsync(); }; cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; TapGestureRecognizer tap = new TapGestureRecognizer(); //tap.Tapped += async (object sender, EventArgs e) => //{ // var result = await DisplayActionSheet("Media Source", "Cancel", null, "Take Picture", "Choose From Gallery"); // // switch (result) // { // case "Cancel": // return; // case "Take Picture": // if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) // { // DisplayAlert("No Camera", "The camera is unavailable.", "OK"); // return; // } // else // { // var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions // { // SaveToAlbum = true, // Directory = "Pictures", // Name = ViewModel.Expense.Id + ".png" // }); // if (file == null) // return; // // var source = ImageSource.FromStream(() => file.GetStream()); // addReceipt.Source = source; // DependencyService.Get<IPhoto>().SavePictureToDisk(source, ViewModel.Expense.Id); // // file.Dispose(); // } // break; // case "Choose From Gallery": // if (CrossMedia.Current.IsPickPhotoSupported) // { // var file = await CrossMedia.Current.PickPhotoAsync(); // // if (file == null) // return; // // var source = ImageSource.FromStream(() => file.GetStream()); // DependencyService.Get<IPhoto>().SavePictureToDisk(source, ViewModel.Expense.Id); // addReceipt.Source = source; // // file.Dispose(); // } // else // { // DisplayAlert("Sorry", "I Can't seem to find the photo gallery, try just taking a picture", "Dang, Ok"); // return; // } // break; // } //}; addReceipt.GestureRecognizers.Add(tap); #endregion }
public ExpenseActionPage(ExpenseModel model = null, bool editable = true) { NavigationPage.SetTitleIcon(this, "icon.png"); ViewModel = new ExpenseActionViewModel(editable); BindingContext = ViewModel; Title = "New Expense"; if (model != null) { ViewModel.Expense = model; } // else // ViewModel.Expense.ReceiptLocation = "ic_insert_photo_white_48dp.png"; AddConditionalUI(); Content = formLayout; Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0); #region Set Bindings And Event Handlers nameEntry.SetBinding(Entry.TextProperty, "Name"); shortDescriptionEntry.SetBinding(Entry.TextProperty, "ShortDescription"); priceEntry.SetBinding(Entry.TextProperty, "Price", BindingMode.TwoWay, null, "$ {0}"); date.SetBinding(DatePicker.DateProperty, "Date"); saveButton.Clicked += (object sender, EventArgs e) => { var success = ViewModel.Save(); if (success) { Navigation.PopModalAsync(); } else { DisplayAlert("Error", "You must enter a Vendor Name, Price and Short Description", "Ok"); } }; cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; TapGestureRecognizer tap = new TapGestureRecognizer(); tap.Tapped += async(object sender, EventArgs e) => { var result = await DisplayActionSheet("Media Source", "Cancel", null, "Take Picture", "Choose From Gallery"); switch (result) { case "Cancel": return; case "Take Picture": if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { DisplayAlert("No Camera", "The camera is unavailable.", "OK"); return; } else { var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = true, Directory = "Pictures", Name = ViewModel.Expense.ExpenseId + ".png" }); if (file == null) { return; } var source = ImageSource.FromStream(() => file.GetStream()); addReceipt.Source = source; DependencyService.Get <IPhoto>().SavePictureToDisk(source, ViewModel.Expense.ExpenseId); file.Dispose(); } break; case "Choose From Gallery": if (CrossMedia.Current.IsPickPhotoSupported) { var file = await CrossMedia.Current.PickPhotoAsync(); if (file == null) { return; } var source = ImageSource.FromStream(() => file.GetStream()); DependencyService.Get <IPhoto>().SavePictureToDisk(source, ViewModel.Expense.ExpenseId); addReceipt.Source = source; file.Dispose(); } else { DisplayAlert("Sorry", "I Can't seem to find the photo gallery, try just taking a picture", "Dang, Ok"); return; } break; } }; addReceipt.GestureRecognizers.Add(tap); #endregion }