I wasted 2 days to figure out whats the issue but I couldnt. I tried all the possible examples, source codes from Github, tutorials, articles etc. I could not bind the List and its contents to a ListView or CollectionView.
Visual studio Version 16.11.3 Xamarin Version
My ViewModel. I tried using list and observable collection.
My CodebehindFile. I tried Binding from Xaml as well as from code behind file.
my Xaml file. I spent 2 days figuring out this Binding issue :(
I wrote a new page which works with basic declaration of ListView contents but...,
I have copied the working code on to the Main page but its not working on the MainPage. The listView which works fine on the other page doesnt work on the main page.
If I comment out the Item template, somehow I see the list of strings bound to the UI.
if I uncomment, I see that Item template works but
If I restart the app, I need to repeat the process. Everything with ListView Binding and collectionView Binding is screwed. We have declare the contents of lists and collections as public properties and access from ViewModel. Its hectic
CodePudding user response:
The issue here is that you had set x:DataType
for the page, which is awesome because it is compiled bindings, however it means you also need to set it on and DataTemplate so it knows the type of the item inside of it. So for the first ListView
that is a string you would do <DataTemplate x:DataType="x:String">
and then for your customer it would be <DataTemplate x:DataType="local:Customer">
Take a look at this repo, seems to work for me based on what I see: https://github.com/jamesmontemagno/App4 & https://github.com/fewbackseven/listView/pull/1