Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 286
Dima Babich Avatar asked Nov 19 '15 09:11

Dima Babich


2 Answers

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);
like image 122
Dushyant Bangal Avatar answered Nov 10 '22 11:11

Dushyant Bangal


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

like image 26
Dima Babich Avatar answered Nov 10 '22 11:11

Dima Babich