public override void OnAttachedToWindow()
 {
     base.OnAttachedToWindow();
     if (CurrentExpense != null && CurrentExpense.Id != 0)
     {
         expenseViewModel.LoadPhotoAsync(CurrentExpense).ContinueWith(_ => {
             activity.RunOnUiThread(() => {
                 if (expenseViewModel.Photo != null)
                 {
                     if (expenseViewModel.Photo.Image != null)
                     {
                         imageBitmap = BitmapFactory.DecodeByteArray(expenseViewModel.Photo.Image, 0, expenseViewModel.Photo.Image.Length);
                         imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight);
                     }
                     expensePhoto.SetImageBitmap(imageBitmap);
                     expenseAddPhoto.Visibility = ViewStates.Gone;
                 }
                 else
                 {
                     expensePhoto.SetImageBitmap(null);
                     expenseAddPhoto.Visibility = ViewStates.Visible;
                 }
             });
         });
         expenseType.SetSelection(expenseTypes.ToList().IndexOf(CurrentExpense.Category));
         expenseAmount.Text       = CurrentExpense.Cost.ToString("0.00");
         expenseDescription.Text  = CurrentExpense.Description;
         deleteExpense.Visibility = CurrentExpense.Id != 0 ? ViewStates.Visible : ViewStates.Gone;
     }
     else
     {
         expenseViewModel.Photo = null;
         expensePhoto.SetImageBitmap(null);
         expenseAmount.Text      = "0.00";
         expenseDescription.Text = string.Empty;
         expenseType.SetSelection(0);
         expenseAddPhoto.Visibility = ViewStates.Visible;
         deleteExpense.Visibility   = ViewStates.Gone;
     }
 }
        public void OnClick(View v)
        {
            switch (v.Id)
            {
            case Resource.Id.addExpenseDelete:
                if (CurrentExpense != null && CurrentExpense.Id != -1)
                {
                    DeleteExpense();
                }
                else
                {
//                        Dismiss ();
                }
                break;

            case Resource.Id.addExpenseSave:
                SaveExpense();
                break;

            case Resource.Id.addExpenseCancel:
//                    Dismiss ();
                break;

            case Resource.Id.addExpenseAddPhoto: {
                var choices = new List <string> ();
                choices.Add(activity.Resources.GetString(Resource.String.Gallery));
                if (mediaPicker.IsCameraAvailable)
                {
                    choices.Add(activity.Resources.GetString(Resource.String.Camera));
                }
                AlertDialog.Builder takePictureDialog = new AlertDialog.Builder(activity);
                takePictureDialog.SetTitle("Select:");
                takePictureDialog.SetItems(choices.ToArray(), (innerSender, innerE) => {
                        if (innerE.Which == 0)
                        {
                            //gallery
                            mediaPicker.PickPhotoAsync().ContinueWith(t => {
                                if (t.IsCanceled)
                                {
                                    return;
                                }
                                activity.RunOnUiThread(() => {
                                    expenseAddPhoto.Visibility = ViewStates.Gone;
                                    imageBitmap = BitmapFactory.DecodeStream(t.Result.GetStream());
                                    imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight);
                                    expensePhoto.SetImageBitmap(imageBitmap);
                                    expenseViewModel.Photo = new ExpensePhoto {
                                        ExpenseId = CurrentExpense.Id
                                    };
                                });
                            });
                        }
                        else if (innerE.Which == 1)
                        {
                            //camera
                            StoreCameraMediaOptions options = new StoreCameraMediaOptions();
                            options.Directory = "FieldService";
                            options.Name      = "FieldService.jpg";
                            mediaPicker.TakePhotoAsync(options).ContinueWith(t => {
                                if (t.IsCanceled)
                                {
                                    return;
                                }
                                activity.RunOnUiThread(() => {
                                    expenseAddPhoto.Visibility = ViewStates.Gone;
                                    imageBitmap = BitmapFactory.DecodeStream(t.Result.GetStream());
                                    imageBitmap = Extensions.ResizeBitmap(imageBitmap, Constants.MaxWidth, Constants.MaxHeight);
                                    expensePhoto.SetImageBitmap(imageBitmap);
                                    expenseViewModel.Photo = new ExpensePhoto {
                                        ExpenseId = CurrentExpense.Id
                                    };
                                });
                            });
                        }
                    });
                takePictureDialog.Show();
            }
            break;

            default:
                break;
            }
        }