Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

ListView Data Binding in XAML

I'm trying to bind a List<> to a ListView. This code was working on WinRT

PostListView.ItemsSource = postList;

<ListView x:Name="PostListView" Grid.Row="1">

       <!--<TextCell Text="{Binding title}"  Detail="{Binding body}"/>-->
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="1*"/>
          <ColumnDefinition Width="2*"/>
          <ColumnDefinition Width="5*"/>

        <Label Grid.Column="0" Text="{Binding userId}"></Label>
        <Label Grid.Column="1" Text="{Binding id}"></Label>
        <Label Grid.Column="2" Text="{Binding title}"></Label>
        <Label Grid.Column="3" Text="{Binding body}"></Label>




ERROR: Unable to cast object of type 'Xamarin.Forms.Grid' to type 'Xamarin.Forms.Cell'.

BUT, when I replace the whole Grid block with this, it works:

<TextCell Text="{Binding title}" Detail="{Binding body}"/>

I want to show 4 different values in a tabular form.

Best Answer


  • RafaelMouraRafaelMoura BRInsider, University, Developer Group Leader ✭✭✭

    Data Template need a ViewCell. The TextCell class extend ViewCell and Grid not. U need Create a ViewCell and put your Grid inside, understand?

  • DushyantBangalDushyantBangal USMember ✭✭

    @RafaelMoura thanks. It worked. :smile:

  • gokcemgokcem USMember


  • 001lilou001lilou FRMember

    Great !! It helped me a lot

Sign In or Register to comment.