Xamarin.forms i want to upload image on same page

245 Views Asked by At

i am uploading my image by using plugins.media but the problem is it redirect to another photoimage page and upload it there.

        var profiletap = new TapGestureRecognizer();

        profiletap.Tapped += async (s, e) =>
        {
           var file = await CrossMedia.Current.PickPhotoAsync();
            if (file == null)
                return;
   await DisplayAlert("File Location", file.Path, "OK");

            ImageSource im = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return stream;

            });




       await Navigation.PushModalAsync(new PhotoPage(im));
        };

        profile.GestureRecognizers.Add(profiletap);

ant here is photopage content

 public class PhotoPage : demopage
{
    public PhotoPage(ImageSource img)
    {
        Content = new Image
        {
            VerticalOptions =LayoutOptions.Start,
            HorizontalOptions = LayoutOptions.Start,
            Source =img
        };
    }
}
1

There are 1 best solutions below

1
On

Instead of doing

await Navigation.PushModalAsync(new PhotoPage(im));

you can do something like

var img = new Image
        {
            Source =im
        };

then add the new img control to the same container as where the "profile" control has already been added (probably some Stacklayout or Grid or some other layout control like that)

Be aware that you are struggling with the most basic concept of building out your app UI, which is a strong indicator you should read some getting started tutorials for xamarin.forms and really understand how the UI is built.