【问题标题】:Binding Image to CarouselView将图像绑定到 CarouselView
【发布时间】:2020-03-12 01:02:45
【问题描述】:

我有一个使用 SQLite 创建的数据库。我正在使用 Xamarin.Forms。我想使用 CarouselView.FormsPlugin 显示图像轮播,虽然我查看了文档,但在我的应用程序上显示它却没有运气。

我在 Android MainActivity.cs 文件中有 CarouselViewRenderer.Init()。但是,没有显示任何图像。

XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:forms="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
             x:Class="HostelRentalApp.HostelDetailsPage">

    <ContentPage.Content>
        <StackLayout>
            <forms:CarouselViewControl x:Name="CRSLImages" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <forms:CarouselViewControl.ItemTemplate HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                    <DataTemplate>
                        <Image Source="{Binding .}"/>
                    </DataTemplate>
                </forms:CarouselViewControl.ItemTemplate>
            </forms:CarouselViewControl>
    </StackLayout>
    </ContentPage.Content>
</ContentPage>

CS:

public HostelDetailsPage (HostelInfo hostel)
        {
            var images = App.Database.GetHostelImageList(0);
            this.CRSLImages.ItemsSource = images;
        }

SQLite 查询:

public List<HostelImages> GetHostelImageList(int id)
        {
            return database.Query<HostelImages>("SELECT Image FROM HostelImages WHERE Hostel_id = ?", id);
        }

查询正在返回正确的行。如图所示,当使用跟踪点时,将检索图像文件名。但是,图像不会显示在 UI 上。我究竟做错了什么?谢谢。

【问题讨论】:

标签: sqlite xaml xamarin xamarin.forms xamarin.android


【解决方案1】:

ItemsSourceList&lt;HostelImages&gt; 所以你的绑定路径应该是

<Image Source="{Binding Image}"/>

【讨论】:

    猜你喜欢
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多