c# - Xamarin FFImageLoading.CachedImage 第一次不显示
问题描述
我在 xamarin 上遇到了 FFImageLoading 的一些故障,发生的事情是图像似乎只在页面第二次重新加载时才显示(例如,我离开页面而不是按后退按钮)我已经尝试加载这些图像首先在加载 ContentPage 之前创建,但它没有工作。我尝试使用 ForceLayout 来显示它,但效果不佳。
这是我在视图中的关注代码
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Tapped="OnDetailsButtonClicked">
<Frame
Margin="2,2,2,2"
Padding="5"
BackgroundColor="White"
IsClippedToBounds="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ffimageloading:CachedImage
x:Name="profilePhoto"
Grid.Row="0"
Grid.Column="0"
Aspect="AspectFit"
HeightRequest="50"
HorizontalOptions="Center"
Source="{Binding CoworkerProfilePhoto}"
VerticalOptions="Center"
WidthRequest="50">
<ffimageloading:CachedImage.Transformations>
<fftransformations:CircleTransformation />
</ffimageloading:CachedImage.Transformations>
</ffimageloading:CachedImage>
....
如您所见,我的投标清单上的 CoworkerProfilePhoto 变量正在投标该文件。
这些图像被存储在设备上,然后显示在屏幕上,这是一个简单的文件保存
public async static Task SaveImagem(this byte[] imagem, String nomeArquivo, IFolder pastaRaiz = null)
{ IFolder 意大利面 = PastaRaiz ?? FileSystem.Current.LocalStorage;
IFile arquivo = await pasta.CreateFileAsync(nomeArquivo, CreationCollisionOption.ReplaceExisting);
using (System.IO.Stream stream = await arquivo.OpenAsync(FileAccess.ReadAndWrite))
{
stream.Write(imagem, 0, imagem.Length);
}
}
任何想法 ?我检查了这两个链接
https://github.com/luberda-molinet/FFImageLoading/issues/238
https://xamarin.github.io/bugzilla-archives/41/41087/bug.html
这似乎是相关的,但它们都没有起作用。
解决方案
我找到了一个适合我的解决方案第一个问题是我只在 CoworkerProfilePhoto 属性中使用文件名
如下图
item.CoworkerProfilePhoto = photo.Name;
但是系统不可能找到文件的存储位置,所以我必须传递绝对的 Uri 文件路径。
如下图
var folder = PCLStorage.FileSystem.Current.LocalStorage.GetFolderAsync(myPath).Result;
item.CoworkerProfilePhoto = new Uri(folder.Path + "/" + photo.Name, UriKind.Absolute);
推荐阅读
- ios - xamarin 表单 ios InAppBillingPlugin 订阅 - 无法连接到 iTunes 商店错误
- javascript - 将模型存储为隐藏输入中的 JSON 并在 javascript 中访问它
- go - SSH 未知 TTY 错误消息
- r - 通过R中的dplyr将特定的列对收集到行中
- reactjs - 反应嵌套组件触摸事件停止传播不起作用/事件冒泡
- r - R:将两个调查问题(因素)归类为一个因素的多个条件,等级为无/轻度/重度
- json - Haskell JSON 解析器改进
- linux - linux上的libbitcoin库构建错误
- python - 训练时调整 Tensorflow nce_loss 中的样本数
- join - 选择连接表包含特定值的位置