我浪費了 2 天的時間來弄清楚是什么問題,但我不能。我嘗試了所有可能的示例、來自 Github 的源代碼、教程、文章等。我無法將 List 及其內容系結到 ListView 或 CollectionView。
Visual Studio 版本 16.11.3 Xamarin 版本

我的視圖模型。我嘗試使用串列和可觀察集合。

我的代碼隱藏檔案。我嘗試從 Xaml 以及從檔案隱藏代碼進行系結。

我的 Xaml 檔案。我花了 2 天的時間來解決這個系結問題:(

模型中的一個簡單類。

我寫了一個新頁面,它使用 ListView 內容的基本宣告,但是...,

我已將作業代碼復制到主頁上,但在主頁上不起作用。在其他頁面上運行良好的 listView 在主頁上不起作用。

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
uj5u.com熱心網友回復:
這里的問題是你已經x:DataType為頁面設定了,這很棒,因為它是編譯系結,但這意味著你還需要將它設定在 DataTemplate 上,以便它知道其中專案的型別。所以對于第一個ListView是你會做的字串<DataTemplate x:DataType="x:String">,然后對于你的客戶來說它會是<DataTemplate x:DataType="local:Customer">
看看這個 repo,根據我所看到的,似乎對我有用:https : //github.com/jamesmontemagno/App4 & https://github.com/fewbackseven/listView/pull/1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/317322.html
標籤:c# listview xamarin.forms binding
