【问题标题】:Xamarin.Forms ListView - Refresh sometimes temporarily hides imagesXamarin.Forms ListView - 刷新有时会暂时隐藏图像
【发布时间】:2019-01-05 00:11:39
【问题描述】:

我的应用程序中有一个列表视图。有时(在 Android 和 iOS 上)下拉刷新会暂时“隐藏”一些图像。这些图像几乎总是会在下次刷新时返回。

这里是设置图片源的代码(试过没有Device.BeginInvokeOnMainThread)

Device.BeginInvokeOnMainThread(() =>
{
    //Set Image value for list item
    listItem.Image = ImageSource.FromResource(String.Format("AppName.FolderName.{0}.png", returnedItem.Description.Replace(" ", "")));
});

这是列表视图的 UI 中的代码:

 <ListView x:Name="listView" HasUnevenRows="True" CachingStrategy="RecycleElement" ItemSelected="ShowItem">
     <ListView.ItemTemplate>
         <DataTemplate>
             <ViewCell>
                 <StackLayout Spacing="5" Orientation="Horizontal" Padding="0,25,0,25" Margin="20,0,20,0">
                     <Image HeightRequest="35" WidthRequest="35" Source="{Binding Path=Image}" VerticalOptions="Center" Margin="0,0,5,0"/>
                     <Label Text="{Binding Path=Name}" FontFamily="{StaticResource BoldFont}" FontSize="19" VerticalTextAlignment="Center"/>
                     <StackLayout HorizontalOptions="EndAndExpand">
                         <Label Text="{Binding Path=Amount}" FontSize="20" TextColor="#b3b3b3" VerticalTextAlignment="Center" FontFamily="{StaticResource MediumFont}" HorizontalOptions="EndAndExpand" HorizontalTextAlignment="End"/>
                        <Label Text="{Binding Path=Value}" FontSize="14" TextColor="#b3b3b3" VerticalTextAlignment="Center" FontFamily="{StaticResource LightFont}" HorizontalOptions="EndAndExpand" HorizontalTextAlignment="End"/>
                     </StackLayout>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

很遗憾,由于我的雇主不允许,我无法显示该应用的任何屏幕截图。但是,我在过去 6 个月中制作了 2 个单独的应用程序,两个应用程序都包含包含图像的列表视图,并且两个应用程序(在两个平台上)都出现了问题。另一个应用程序包含非常相似的列表视图代码。

注意:图像存储在主项目的文件夹中,并配置为具有“嵌入式资源”的构建操作(按照 Microsoft here 的说明)。

以前有没有人遇到过这个问题,或者任何人都可以提供解决方法吗?

【问题讨论】:

    标签: listview xamarin.forms


    【解决方案1】:

    解决方案:我更改了存储图像的方式,使用 Android 的资源文件夹(可绘制)和 Apple 的资产目录。 然后我将代码修改为:

    listItem.Image = ImageSource.FromFile(String.Format(${returnedItem.Description.Replace(" ", "")}.png"));

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      相关资源
      最近更新 更多