简体   繁体   English

Xamarin表单(Xaml)ListView不显示图像

[英]Xamarin Forms (Xaml) ListView not displaying images

My XAML looks like this: 我的XAML如下所示:

<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         x:Class="MyApp.Mobile.MyPage">
<ContentPage.Content>
    <StackLayout>
        <Image Source="http://MyUrl/MyImage.png" />  <!-- WORKS -->
        <ListView ItemsSource="{Binding Cells}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical">
                            <Label Text="{Binding RowName}" />
                            <Label Text="{Binding ColumnName}" />
                            <Image Source="http://MyUrl/MyImage.png" /> <!-- DOES NOT WORK-->
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

Xamarin Forms (testing on Android) The first image displays fine. Xamarin Forms(在Android上测试)第一张图像显示正常。 The very same image in the ListView does not display. ListView中的图像完全不显示。 Ultimately I will using a Binding like the Labels (which work), but I have hard coded the URL as I diagnose the issue. 最终,我将像标签一样使用绑定(可以使用),但是在诊断问题时已经对URL进行了硬编码。

Does anyone know why the Image is not displaying in the ListView? 有谁知道为什么Image没有显示在ListView中?

Try like below, 尝试如下

<ListView 
            HasUnevenRows="True"
            ItemsSource="{Binding Cells}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Vertical">
                            <Label Text="{Binding RowName}" />
                            <Label Text="{Binding ColumnName}" />
                            <Image Source="http://xamarin.com/content/images/pages/index/hero.jpg" />
                            <!-- DOES NOT WORK-->
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

It is working checked at my end. 我的工作正在检查中。

Happy Coding.. 快乐编码

Kishore Kumar Vangala. Kishore Kumar Vangala。

I higly suggest to use FFImageLoading when dealing with images in listview. 我建议在处理列表视图中的图像时使用FFImageLoading The performance gain and optimized memory consumption is huge! 性能提升和优化的内存消耗是巨大的! Github | Github | Nuget 努吉特

Then in listview, in order to avoid issues with cell sizing, is better to specify HeightRequest and WidthRequest to your Image , then use an Aspect that fits your need ( AspectFit , AspectFill , ecc...) 然后在listview中,为了避免像元大小调整问题,最好为Image指定HeightRequestWidthRequest ,然后使用适合您需要的AspectAspectFitAspectFill ,ecc ...)

Just tested now and everything is working without issues. 现在刚刚测试,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM