Reputation: 597
I want is to pass an image into another page through bindingcontext
This is the page where the image is already bound and when it is tapped I want to fetch it to another page.
<Image Source="{Binding Image}"
x:Name="image1"
HeightRequest="200"
WidthRequest="200"
IsEnabled="True"
Aspect="Fill"
Margin="10">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="TapGestureRecognizer_Tapped"
NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
This is where I am passing the image to another page
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var page = new Page1();
page.BindingContext = image1.Source;
await Navigation.PushPopupAsync(page);
}
This is the code of the second page that takes the image
<Image Source="{Binding Image}" Aspect="Fill"/>
The problem is that the image is not showing the second page. What's wrong with the code?
Upvotes: 0
Views: 927
Reputation: 1946
As per your code, You have bound the second page with first page's image source. So, your second-page binding context is image source. So, you can use it as per my solution.
This is the code of the second page that takes the image
<Image Source="{Binding .}" Aspect="Fill"/>
Create new property for image source (like ImageSource) in second page viewmodel and assign it from first page and use this property on second page like below:
<Image Source="{Binding ImageSource}" Aspect="Fill"/>
Upvotes: 1