xamarin forms change ffimage programmatically

368 views Asked by At

I'm struggling with changing an image programmatically.

In xaml I have an image like:

<ffimageloading:CachedImage x:Name="n3" Source="N3.png" ></ffimageloading:CachedImage>

In Code I have a TapGesture Recognizer:

var tapn3 = new TapGestureRecognizer();
            tapn3.Tapped += tapn3_Tapped;
            n3.GestureRecognizers.Add(tapn3);

And the corresponding event:

async private void tapn3_Tapped(object sender, EventArgs e)
        {
            string level = GetLevel();
            if (level == "N3") {
                   // n3.Source = new Image (Source "n3.png");
            } else {
                  // n3.Source = new Image (Source "n4.png");
            }
        }

GetLevel, returns a string which is stored in a SQLite DB, and that is working fine.

Off course, the commented lines is the functionality I'm not able to resolve.

1

There are 1 answers

2
Gerald Versluis On BEST ANSWER

If the images are already in your app, you should be able to do this: n3.Source = ImageSource.FromFile("n3.png");