locked
Don't work binding in Native ListView RRS feed

  • Question

  • User388063 posted

    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

    Sunday, April 12, 2020 7:44 PM

Answers

  • User371688 posted

    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

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, April 13, 2020 9:45 AM

All replies

  • User371688 posted

    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

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, April 13, 2020 9:45 AM
  • User388063 posted

    @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!

    Monday, April 13, 2020 11:44 AM