xamarin 表单以编程方式更改 ffimage
xamarin forms change ffimage programmatically
我正在努力以编程方式更改图像。
在 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,returns 一个存储在 SQLite 数据库中的字符串,并且工作正常。
当然,注释行是我无法解决的功能。
如果图像已经在您的应用中,您应该可以这样做:n3.Source = ImageSource.FromFile("n3.png");
我正在努力以编程方式更改图像。
在 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,returns 一个存储在 SQLite 数据库中的字符串,并且工作正常。
当然,注释行是我无法解决的功能。
如果图像已经在您的应用中,您应该可以这样做:n3.Source = ImageSource.FromFile("n3.png");