I am trying to populate a ListView from a data. In my XAML file I have written
<?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="FormDemos.Views.Feedback">
<ContentPage.Content>
<Label>I am Testimonials Page</Label>
<ListView x:Name="FeedbackList" />
</ContentPage.Content>
</ContentPage>
In CS file
namespace FormDemos.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Feedback : ContentPage
{
class City
{
public string Name
{
get;
set;
}
public string State
{
get;
set;
}
}
public Feedback()
{
InitializeComponent();
var cities = new List<City>() {
new City() {State = "FL", Name = "Miami"},
new City() {State = "CA", Name = "San Francisco"},
new City() {State = "CA", Name = "Los Angeles"},
new City() {State = "FL", Name = "Orlando"},
new City() {State = "TX", Name = "Houston"},
new City() {State = "NY", Name = "New York City"},
};
FeedbackList.ItemsSource = cities;
}
}
}
Everytime I build this project I get Error "Sequence contains no elements". I have seen some online tutorials have the same code and running well. What's going wrong here?
You have to include controls inside a layout
<?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="FormDemos.Views.Feedback">
<ContentPage.Content>
<StackLayout>
<Label>I am Testimonials Page</Label>
<ListView x:Name="FeedbackList" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
I have written this little article about this...
Sometimes this happens when you have a ListView with Bindings and when you forget to add Binding keyword
Eg: {Binding Name}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With