listview xamarin表单中滚动时图像消失
我有xamarin格式的ListView。上下滚动此列表视图时,此时钟图像会不一致地出现和消失 即使我硬编码可见性,图像也不一致listview xamarin表单中滚动时图像消失,listview,xamarin,xamarin.forms,Listview,Xamarin,Xamarin.forms,我有xamarin格式的ListView。上下滚动此列表视图时,此时钟图像会不一致地出现和消失 即使我硬编码可见性,图像也不一致 <DataTemplate x:Key="itemTemplate"> <ViewCell> <StackLayout Orientation="Horizontal" Spacing="5" Padding="0,0,10,0"> &l
<DataTemplate x:Key="itemTemplate">
<ViewCell>
<StackLayout Orientation="Horizontal" Spacing="5" Padding="0,0,10,0">
<Label HorizontalOptions="StartAndExpand" VerticalOptions="Center" TextColor="#455560" Text="{Binding DispenseTypeWithMachineCount}" WidthRequest="250"/>
<Image IsVisible="{Binding IsServiceInProgress}" Source="ic_progress.png" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="EndAndExpand"/>
</StackLayout>
</ViewCell>
</DataTemplate>
<ListView x:Name="ListViewAccounts" Margin="0,0,0,0" ItemsSource="{Binding ExpandedGroups}" GroupDisplayBinding="{Binding Title}" IsGroupingEnabled="true" ItemTemplate="{StaticResource accountTemplateSelector}" GroupHeaderTemplate="{StaticResource groupHeaderTemplate}">
<ListView.Behaviors>
<behaviors:EventToCommandBehavior EventName="ItemTapped" Command="{Binding Path=BindingContext.ListViewAccountItemTappedCommand Source={x:Reference ListViewAccounts}}" />
</ListView.Behaviors>
<x:Arguments>
<ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy>
</x:Argume
回收元素
我以前也有过关于运动图像的问题,它们的行为是不一致的。我已经解决了大多数问题,尽可能使用矢量化图标,而不是图像文件,这似乎适合您的情况,因为您也使用图标
我建议使用FFImageLoading(如前所建议)加载SVG,它加载速度快,并缓存它们以备将来使用。执行以下操作以替换对SVG的PNG引用:
从NuGet软件包管理器安装并安装到项目中
从FontAwesome下载
将图标放在项目的文件夹中,并将其生成操作设置为嵌入资源
将FFImageLoading引用添加到XAML的顶部:
将数据模板
中的图像
元素替换为以下内容:
例如:
<ffsvg:SvgCachedImage IsVisible="{Binding IsServiceInProgress}" Source="resource://MyProject.Resources.clock.svg" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="EndAndExpand"/>
SVG负载较轻,分辨率较高,应解决闪烁问题
另一件可能有帮助的事情是搞乱ListCachingStrategy
属性,因为它定义了列表中元素的缓存和呈现方式。查看有关ListView性能的更多信息。您还可以更改列表视图回收元素的方式,我注意到您正在实现它,但您的操作看起来很奇怪:
战略类型:
保留默认值//默认值
RecycleElement
RecycleElementAndDataTemplate
列表视图:
这可能是因为加载图像需要时间,请检查图像大小是否过大。并使用FFloading.Forms CachedImage with Cache=始终如果您想在使用FFloading的图像上获得更好的性能…静止图像在剧烈滚动时消失…您的XF版本是什么?我不能重复您的问题,您可以尝试更新XF。@LeoZhu MSFT我使用的是XF 4.1。。。仍然是相同的问题…时钟img是否在lsitview组头中?
<ffsvg:SvgCachedImage IsVisible="{Binding IsServiceInProgress}" Source="resource://[PATH_TO_YOUR_SVG_INSIDE_NAMESPACE].clock.svg" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="EndAndExpand"/>
<ffsvg:SvgCachedImage IsVisible="{Binding IsServiceInProgress}" Source="resource://MyProject.Resources.clock.svg" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" HorizontalOptions="EndAndExpand"/>