首页 > 解决方案 > xamarin 表单以编程方式更改 ffimage

问题描述

我正在努力以编程方式更改图像。

在 xaml 我有一个像这样的图像:

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

在代码中,我有一个 TapGesture 识别器:

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

以及相应的事件:

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,返回一个存储在 SQLite DB 中的字符串,并且工作正常。

当然,注释行是我无法解决的功能。

标签: c#xamarin.formsffimageloading

解决方案


如果图像已经在您的应用程序中,您应该可以这样做:n3.Source = ImageSource.FromFile("n3.png");


推荐阅读