Dima
Dima

Reputation: 464

Xamarin - blinking when i replace image source

I am working with xamarin forms and trying to create navigation menu. I need to set new image when i click on cell. I have some blinking when i replace image.

I create image:

var image = new Image { Source = "Image.png"; }

I add it on my grid

    var profileTapRecognizer = new TapGestureRecognizer();
                profileTapRecognizer.Tapped += (sender, e) =>
                {
                    ItemClicked(sender as ITaggedCell);
                };

        image.GestureRecognizers.Add(profileTapRecognizer);

    grid.Children.Add(image, i, 0);

And in ItemClicked i change source and have blink before new image was set:

image.Source = "NewImage.png" 

I tried

image.BatchBegin() 
image.Source = "NewImage.png" 
image.BatchCommit() 

and this way How to change Image Source while clicking on the ListView in xamarin.forms?

What is the best way to change image?

Upvotes: 7

Views: 4250

Answers (2)

Dima
Dima

Reputation: 464

I found the solution - to add two images and change opacity to 0/1

Upvotes: 3

Dushyant Bangal
Dushyant Bangal

Reputation: 6403

Not a direct solution, but if you're changing image, why not animate? that would even look good!

First fade out, then replace, then fade in!

await image.FadeTo(0, 250);
image.Source = "NewImage.png";
await image.FadeTo(1, 250);

Upvotes: 13

Related Questions