在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'并会查看绑定是否有效。 –