amaro tati
amaro tati

Reputation: 55

how change the picture by clicking on it

I have two images of the same type one blue and the other pink to simulate the click on the image, so when I click on the image it calls one screen without first calling the other image. what I want is before calling the other screen, clicking on the initial image that is blue change to pink and only then calls the screen.

 <Image x:Name="CmdCalendario" Grid.Row="0" Grid.Column="0" Source="calendarioFiscallivre.png"  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"  />

So I would like to click on the image before changing to the pink image that is in the code behind and then call the screen.

  var CalendarioClick = new TapGestureRecognizer();
            CalendarioClick.Tapped += (s, e) =>
            {
                CmdCalendario.Source = ImageSource.FromResource("Agtmovel.Img.calendarioFiscalpressed.png");
                Navigation.PushAsync(new CalendarioFiscal());

            }; CmdCalendario.GestureRecognizers.Add(CalendarioClick);

Upvotes: 0

Views: 72

Answers (2)

nevermore
nevermore

Reputation: 15816

The code in the CalendarioClick.Tapped is synchronous and they will execute in order. The imageSoure really changed before you push to a new page, however the process of changing is very fast and you can't even figure it out.

Solution:

You can add a short delay before push to a new page. You can define the delay time whatever you what.

var CalendarioClick = new TapGestureRecognizer();
              CalendarioClick.Tapped += async (s, e) =>
                  {
                      CmdCalendario.BackgroundColor = Color.Pink;
                      //Delay 2000ms, change the time you want here
                      await Task.Delay(2000);
                      Navigation.PushAsync(new CalendarioFiscal());

                  }; 
        CmdCalendario.GestureRecognizers.Add(CalendarioClick);

Refer :Async and Await

Upvotes: 1

Bruno Caceiro
Bruno Caceiro

Reputation: 7199

You can use FlexButton for simulate click on images

<flex:FlexButton
    WidthRequest="76"
    HeightRequest="76"
    CornerRadius="38"
    HorizontalOptions="Center"
    Icon="lightbulb.png"
    ForegroundColor="#ffffff"
    HighlightForegroundColor="#49516F"
    BackgroundColor="#6279B8"
    HighlightBackgroundColor="#8EA4D2" />

Upvotes: 0

Related Questions