我在使用ListView在xaml中獲取數據綁定的問題。 ListView按預期方式顯示所有單元格,但不顯示任何綁定變量的值。Xamarin:使用列表在xcml中填充ListView <T>
我有樣本數據構造是這樣的:
public class DataItem
{
public int Number { get; set; }
public string Message { get; set; }
public DataItem (int i)
{
this.Number = i + 1;
this.Message = string.Format ("Data Item Hello {0}", i + 1);
}
}
在XAML中的ListView定義是這樣的:
<ListView x:Name="uiList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical" BackgroundColor="Silver">
<Label TextColor="Green" Text="Pre Xamarin" />
<Label BackgroundColor="Aqua" TextColor="Red" Text="{Binding Path=Message}" />
<Label TextColor="Green" Text="Hello Xamarin" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我已創建200個樣本對象和分配給uiList.ItemsSource。這會導致ListView按預期顯示200個項目,但它不顯示DataItem中的Message
屬性的值。
我也嘗試使用{綁定消息}(沒有路徑=),但結果沒有改變。我確定有一些明顯的我失蹤,但無法弄清楚。
---更新---
我現在有一個可靠的repro。創建一個新項目並添加上面提供的ListView和人口。
轉到iOS項目的解決方案屬性,選擇iOS Build頁面並將「鏈接行爲」更改爲「全部鏈接」,並將「支持的體系結構」更改爲「x86_64」。現在清潔,構建和運行,綁定將不起作用。
也許有你的模擬器/設備舊引用。清理並重建您的項目,因爲您的代碼似乎有效(根據一個答案)。 –