c# - 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 中的字符串,并且工作正常。
当然,注释行是我无法解决的功能。
解决方案
如果图像已经在您的应用程序中,您应该可以这样做:n3.Source = ImageSource.FromFile("n3.png");
推荐阅读
- flutter - 在点击另一个小部件时使小部件显示 Flutter
- mysql - 如何从 Windows 10 中完全删除 MySQL,包括缓存的 root 密码?
- windows - 删除后Git仍然要求密钥?
- python-3.x - 使用python计算图像中的星数
- typescript - 在 vue 和 typescript 中通过 id 获取元素
- nlp - 如何解决 Kaldi ASR 特征提取错误?
- flutter - Future 执行后不显示小部件
- amazon-web-services - 低级多部分上传性能问题
- aframe - 如何从 HTML 按钮回调启动 WebXR?
- html - 我在使用 HTML 设计的网站中有一个“<<”元素