listview - 在 ListView Xamarin 表单中滚动时图像消失

标签 listview xamarin xamarin.forms

ListView Xamarin forms

我有 xamarin 形式的 ListView。上下滚动此 ListView 时,此时钟图像的出现和消失不一致。

即使我对可见性进行硬编码,图像也不一致。

<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

最佳答案

您还可以更改 ListView 回收元素的方式,我注意到您正在实现它,但您的看起来很奇怪:

策略类型:

  • RetainElement//默认值

  • RecycleElement

  • RecycleElementAndDataTemplate

ListView :

<ListView
    x:Name="ListViewAccounts"
    Margin="0,0,0,0"
    ItemsSource="{Binding ExpandedGroups}"
    GroupDisplayBinding="{Binding Title}"
    IsGroupingEnabled="true"
    ItemTemplate="{StaticResource accountTemplateSelector}"
    CachingStrategy="RecycleElement"
    GroupHeaderTemplate="{StaticResource groupHeaderTemplate}">
    <ListView.Behaviors>
        <behaviors:EventToCommandBehavior
            EventName="ItemTapped"
            Command="{Binding Path=BindingContext.ListViewAccountItemTappedCommand,  Source={x:Reference ListViewAccounts}}" />
    </ListView.Behaviors>
</ListView>

关于listview - 在 ListView Xamarin 表单中滚动时图像消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57017480/

相关文章:

android - 从 ListView 按钮打开自定义 AlertDialog 单击

android - ListView 中自定义可检查元素的初始状态 "checked"

java - 在 addListener 中从 ListView 中删除项目

coding-style - 从 Xamarin Studio 中的项目中删除未使用的代码/文件

c# - Xamarin.Forms 选择器默认值

android - ListFragment 项选中的背景

c# - 在 Xamarin.Forms 中的 ListView 末尾加载更多项目

c# - 您如何根据登录状态/角色限制/控制用户可以访问的导航路线?

c# - 在屏幕中缩小时,部分 View 神奇地消失了(Android 上的 Xamarin Forms)

android - 更改 Xamarin Forms Picker 按钮样式