Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 76418

ListView Data Binding in XAML

$
0
0

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">
  <ListView.ItemTemplate>
    <DataTemplate>

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

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

      </Grid>

    </DataTemplate>


  </ListView.ItemTemplate>
</ListView>

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.


Viewing all articles
Browse latest Browse all 76418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>