I want to display an image upon clicking on a label. Any help?
I know how to make a label clickable but what would be the approach to display an image thereafter?
Add TapGestureRecognizer on the Label , and manipulate image's IsVisible
to true in the tap event.
<ContentPage.Content> <StackLayout> <Label Text="Welcome to Xamarin.Forms!" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" > <Label.GestureRecognizers> <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/> </Label.GestureRecognizers> </Label> <Image x:Name="image" Source="dog2.png" IsVisible="False"/> </StackLayout> </ContentPage.Content>
private void TapGestureRecognizer_Tapped(object sender, EventArgs e) { image.IsVisible = true; }
Answers
set IsVisible property of the image.
This is what I have tried:
xaml:
.cs:
Add TapGestureRecognizer on the Label , and manipulate image's
IsVisible
to true in the tap event.Xaml
Code