在Xamarin.Forms中我有一個顯示數據庫項目的頁面。XAML綁定到標籤
public ListItemsPage()
{
DatabaseHelper tmpDBHelper = new DatabaseHelper();
InitializeComponent();
listView.ItemsSource = tmpDBHelper.GetItems();
}
這些項目有4列:id作爲Guid
,MandantId爲Guid
,UpdateAt爲DateTime
和URL作爲String
。
現在我想在我的XAML中像這樣綁定它們。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Portable.Pages.ListItemsPage"
Title="DbItemExample">
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Padding="20,0,20,0"
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Label Text="{Binding Id}"
HorizontalOptions="StartAndExpand" />
<Label Text="{Binding Url}"
HorizontalOptions="StartAndExpand" />
<Label Text="{Binding MandantId}"
HorizontalOptions="StartAndExpand" />
<Label Text="{Binding UpdateAt}"
HorizontalOptions="StartAndExpand" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
如果這有幫助,這是我的模型的數據庫表生成。
class DbItem
{
[PrimaryKey]
public Guid Id { get; set; }
public Guid MandantId { get; set; }
public string Url { get; set; }
public DateTime UpdateAt { get; set; }
}
它只顯示Url和UpdateAt。這是爲什麼?
'Url'和'MandantId'來自數據庫嗎? –
@EgorGromadskiy是的,他們這樣做。我獲得了具有所有屬性的cs文件中的項目。 – greenhoorn
我會添加'EmptyConverter'並會查看綁定是否有效。 –