Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Don't work binding in Native ListView

I make Native ListView with FFImageLoading by this guide - site, but items don't binding. Tell me please, why?
I reviewed all the code, everything seems to be correct.
Maybe this method of assignment does not work for me?

SearchViewCell.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="400">

    <sample.droid.cells.MyImageView
        android:id="@+id/SearchViewImage"
        android:src=""
        android:layout_width="195.0dp"
        android:layout_height="251.5dp"/>

    <TextView
        android:id="@+id/SearchViewTitle"
        android:layout_below="@+id/SearchViewImage"
        android:text=""
        android:textSize="24dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:background="#FFFFFF"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="6dp" />
</RelativeLayout>

SearchViewCellRenderer - https://pastebin.com/qrLtGkGk
SearchItem and SearchViewCell - https://pastebin.com/gCDxfz9g
Page - https://pastebin.com/dNTte00K

Best Answer

Answers

  • DiamondKeshaDiamondKesha Member ✭✭

    @jezh said:
    From the code you post as follows, we could find that the ItemsSource is Items,and the Items is a list of SearchItem

    <ListView x:Name="animeItems" ItemsSource="{Binding Items}" CachingStrategy="RecycleElement" SeparatorVisibility="None" HasUnevenRows="True" Scrolled="animeItems_Scrolled">
        <ListView.ItemTemplate>
            <DataTemplate>
                <cells:SearchViewCell SearchItem="{Binding}"/>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    The Items:

    public ObservableCollection<SearchItem> Items { get; set; }
    Items.Add(new SearchItem
        {
            PhotoUrl = "photo url...",
            Title = "name..."
        });
    

    And the class SearchItem is a model which include fields PhotoUrl and Title, so we couldn't bind the value by code <cells:SearchViewCell SearchItem="{Binding}"/>
    we should bind the special field of SearchItem. For example:

        <StackLayout Spacing="0" Margin="0,0,0,6" BackgroundColor="Silver">
                                      <ff:CachedImage DownsampleWidth="640" Aspect="AspectFill" Source="{Binding PhotoUrl}" HorizontalOptions="FillAndExpand" HeightRequest="300" />
                                      <Label Text="{Binding Title,StringFormat='Title:{0:N}'}" />
       </StackLayout>
    

    For more details,you can refer to class the sample code of MainPage.xaml

     
    

    Ah, I thought that binding items in SearchViewCell.xml.
    Thank you!

Sign In or Register to comment.