locked
CollectionView Data isn't loaded RRS feed

  • Question

  • User390943 posted

    Hi everyone,

    I hope you can help me with my issue.

    I created a ContentPage with the following ListView. So the important part is the TemplateForAndroid.

    ```xaml

    <ListView.Behaviors>
        <local:EventToCommandBehaviour EventName="ItemAppearing" Command="{Binding LoadMoreCommand}"/>
    </ListView.Behaviors>
    
    <ListView.ItemTemplate>
            <OnPlatform x:TypeArguments="DataTemplate">
                <On Platform="iOS" Value="{StaticResource TemplateForiOS}"/>
                <On Platform="Android" Value="{StaticResource TemplateForAndroid}"/>
            </OnPlatform>
    </ListView.ItemTemplate>
    

    ```

    The TemplateForAndroid looks as following: xaml <ViewCell 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" xmlns:converter="clr-namespace:CommunityApp.Converter;assembly=CommunityApp" x:Class="CommunityApp.Views.NotificationViewCell"> <ViewCell.View> <CollectionView x:Name="NotiScroll" ItemsLayout="HorizontalList"> <CollectionView.Resources> <ResourceDictionary> <converter:HtmlLabelConverter x:Key="HtmlLabelConverter" /> </ResourceDictionary> </CollectionView.Resources> <CollectionView.ItemTemplate> <DataTemplate> <StackLayout Orientation="Horizontal"> <Label Grid.Row="0" Grid.Column="0" HeightRequest="30" Text="Test" FontAttributes="Italic" VerticalOptions="End" /> <Label Grid.Row="0" Grid.Column="0" HeightRequest="30" Text="Test" FontAttributes="Italic" VerticalOptions="End" /> <Label Grid.Row="0" Grid.Column="0" HeightRequest="30" Text="Test" FontAttributes="Italic" VerticalOptions="End" /> </StackLayout> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ViewCell.View> </ViewCell>

    At the moment I try to work with dummy Labels, but even those are not visible in my Android App. So The ListView works good but the Labels from the DataTemplate inside the ViewCell isn't visible or doesn't get loaded.

    If you have further questions, please ask me.

    Greetings

    Tuesday, March 10, 2020 5:59 PM

Answers

  • User369978 posted

    It works fine on my side , check the sample .

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 11, 2020 6:59 AM

All replies

  • User369978 posted

    You should set ItemsSource on the CollectionView in custom viewcell .

     <CollectionView ItemsLayout="HorizontalList" ItemsSource="{Binding .}">
    
    Wednesday, March 11, 2020 3:40 AM
  • User369978 posted

    Does my answer help or not ?

    Wednesday, March 11, 2020 6:50 AM
  • User390943 posted

    Thank you for your fast response. :)

    Sadly this didn't work for me. I also tried to copy my collection view inside my ContentPage to see if this does the trick (maybe the error appears because of the custom ViewCell), but still, the DataTemplate isn't visible.

    Wednesday, March 11, 2020 6:55 AM
  • User369978 posted

    It works fine on my side , check the sample .

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, March 11, 2020 6:59 AM
  • User390943 posted

    Thank you for this sample. Figgered out, that it doesn't work what I tried to achieve, because my ItemSource is not from type IEnumerable (at least I think, that this is the problem).

    I tried to work with CollectionView to use the SnapPoint feature.

    So the last question. Is there a way to use SnapPoint or something comparable for ScrollViews? (see Microsoft Doc -> CollectionView -> Scrolling -> Snappoint)

    Wednesday, March 11, 2020 1:11 PM
  • User397882 posted

    @ColeX said: It works fine on my side , check the sample .

    how to use fontawesome5 inside collectionview? pls help :(

    Friday, December 4, 2020 8:23 AM