Home > Net >  It seems Xamarin ListView binding is broken in updated VS 2019 16.11.3. CollectionView binding too.
It seems Xamarin ListView binding is broken in updated VS 2019 16.11.3. CollectionView binding too.

Time:10-06

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 enter image description here

My ViewModel. I tried using list and observable collection. enter image description here

My CodebehindFile. I tried Binding from Xaml as well as from code behind file. enter image description here

my Xaml file. I spent 2 days figuring out this Binding issue :( enter image description here

A simple class in the model. enter image description here

I wrote a new page which works with basic declaration of ListView contents but..., enter image description here

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. enter image description here

If I comment out the Item template, somehow I see the list of strings bound to the UI. enter image description here

if I uncomment, I see that Item template works but enter image description here

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

  • Related