I have been trying to populate the data template inside the listview but it does not display anything. My code below:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BlueDemo.ScoreDisplay">
<ContentPage.Content>
<StackLayout>
<ListView x:Name="listView" Grid.ColumnSpan="2">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*"/>
<ColumnDefinition Width="0.3*"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding name}" FontAttributes="Bold"/>
<Label Text="{Binding score}" Grid.Column ="1"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
public partial class ScoreDisplay : ContentPage
{
public static List<int> Score = new List<int>();
public static List<string> Name = new List<string>();
public string[] nme = new string[10];
public static int[] scr = new int[10];
public ObservableCollection<Data> mySource{get;set;}
public ScoreDisplay()
{
InitializeComponent();
BindingContext = this;
nme = Name.ToArray();
scr=Score.ToArray();
mySource = new ObservableCollection<Data>();
for(int i=0;i<nScore.Count;i++)
{
mySource.Add(nnew Data {name = nme[i], score =
scr[i].ToString()});
}
listView.ItemsSource = mySource;
}
}
public class Data
{
public string name { get; set; }
public string score { get; set; }
}
I have two lists (Name and Score) that are getting the value from other page. I am not sure how to bind each and every value in them with Name and Score of listview. EDIT: Working code