I need to fill simple ListView with data, but listView is still null and i dont know why. Code (xaml):
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SecuKey"
x:Class="SecuKey.TransactionViewController">
<ListView x:Name="MainListView"
HasUnevenRows="True" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Name}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
and c#:
using System;
using System.Collections.Generic;
using SecuKey.Controllers.ViewControllers;
using Newtonsoft.Json;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace SecuKey
{
public class ListViewTemplate
{
public string Name { get; set; }
}
public partial class TransactionViewController : ContentPage
{
public TransactionViewController()
{
// Just for test
MainListView.ItemsSource = new List<ListViewTemplate> {
new ListViewTemplate
{
Name = "Xamarin.Forms",
},
new ListViewTemplate
{
Name = "Android",
},
new ListViewTemplate
{
Name = "IOS",
},
new ListViewTemplate
{
Name = "Windows",
}
};
}
}
problem is here: MainListView.ItemsSource = new List {} becouse MainListView is null... Any advice please? I followed a tutorial and there isnt something more..
Thank you