# Visual Basic > Xamarin >  After photo gallery browsing it goes back to the first page

## vuyiswamb

Good Day 

in my Xamarin page i have a button that browse the gallery to allow a user to bind it to an image editor , after selecting the image , the page refreshes to the first page that led to this current page. i would like to make it keep it in the current page after image selection . below is the code on my button 



```
async private void Btnupload_Clicked(object sender, EventArgs e)
        {
            GenericMethods.IS_IMAGE_SELECTON = true;
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                    return;
                }
                var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
                });

                if (file == null)
                    return;

                filePath = file.Path;
                paths.Enqueue(filePath);

                //Linux path 
                readytosave = GenericMethods.StreamToByteArray(file.GetStream());

                Uri uri = new Uri(file.Path);
                filename = string.Empty;
                if (uri.IsFile)
                {
                    filename = System.IO.Path.GetFileName(uri.LocalPath);
                }
                var extension = filename.Split('.')[1].ToLower();

                file_extension = extension;

                 imageEditor.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return stream;
                });
            imagepopup.IsOpen = true;
        }
```

Thanks

----------


## HarshShah

Display an ActionSheet with Prism.IPageDialogService to give choices to the user.

Method for a button.



```
private async void AddImage() // This is your method for your button
{
    string chosen = await _dialogService.DisplayActionSheetAsync("Which source do you want to use?", "Cancel", null, "Camera", "Galery");
    if (chosen == "Camera")
    {
        TakePhoto();
    }
    else if (chosen == "Galery")
    {
        PickPhoto();
    }
}
```

Implementation of TakePhoto()



```
private async void TakePhoto()
{
    await CrossMedia.Current.Initialize();

    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
    {
        await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
        return;
    }

    _mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        SaveToAlbum = true,
        Directory = "Sample",
        Name = "sample" + DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + ".jpg"
    });

    if (_mediaFile == null)
    {
        return;
    }

    ImageButtonAddGroup = _mediaFile.Path;
}
```

Implementation of PickPhoto()



```
private async void PickPhoto()
{
    await CrossMedia.Current.Initialize();

    if (!CrossMedia.Current.IsPickPhotoSupported)
    {
        await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
        return;
    }

    _mediaFile = await CrossMedia.Current.PickPhotoAsync();
    if (_mediaFile == null)
    {
        return;
    }
    ImageButtonAddGroup = _mediaFile.Path;
}
```

Using this code you can select a pic from gallery and take a pic from camera.

----------


## HarshShah

Display an ActionSheet with Prism.IPageDialogService to give choices to the user.

Method for a button.



```
private async void AddImage() // This is your method for your button
{
    string chosen = await _dialogService.DisplayActionSheetAsync("Which source do you want to use?", "Cancel", null, "Camera", "Galery");
    if (chosen == "Camera")
    {
        TakePhoto();
    }
    else if (chosen == "Galery")
    {
        PickPhoto();
    }
}
```

Implementation of TakePhoto()



```
private async void TakePhoto()
{
    await CrossMedia.Current.Initialize();

    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
    {
        await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
        return;
    }

    _mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        SaveToAlbum = true,
        Directory = "Sample",
        Name = "sample" + DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + ".jpg"
    });

    if (_mediaFile == null)
    {
        return;
    }

    ImageButtonAddGroup = _mediaFile.Path;
}
```

Implementation of PickPhoto()



```
private async void PickPhoto()
{
    await CrossMedia.Current.Initialize();

    if (!CrossMedia.Current.IsPickPhotoSupported)
    {
        await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
        return;
    }

    _mediaFile = await CrossMedia.Current.PickPhotoAsync();
    if (_mediaFile == null)
    {
        return;
    }
    ImageButtonAddGroup = _mediaFile.Path;
}
```

Using this code you can select a pic from gallery and take a pic from camera.

----------

