【发布时间】:2016-04-28 23:10:15
【问题描述】:
我正在使用基于 SQLLite 的小型数据库构建应用程序。这在 Windows Phone 上运行良好。现在我正试图让它与 Xamarin Forms (Portable) 一起使用。表格的数据库构建和填充工作正常。现在我试图在 ListView 中显示表格的元素,但是在 ListView 中获取表格注释的项目时遇到问题。 My Table Notes 设置完毕,里面有两个 Item:
public class Notes
{
//The Id property is marked as the Primary Key
[SQLite.PrimaryKey, SQLite.AutoIncrement]
public int Id { get; set; }
public string Note { get; set; }
public DateTimeOffset NoteDate { get; set; }
public TimeSpan NoteStart { get; set; }
public Notes()
{
}
public Notes(string remark, DateTimeOffset notedate, TimeSpan noteStart)
{
Note = remark;
NoteDate = notedate;
NoteStart = noteStart;
}
}
db.Insert(new Notes("Test", DateTimeOffset.Now.AddDays(0), TimeSpan.Parse("7:45")));
db.Insert(new Notes("Test", DateTimeOffset.Now.AddDays(1), TimeSpan.Parse("7:45")));
我用以下方式调用项目:
public IEnumerable<Notes> GetItems()
{
{
return (from i in db.Table<Notes>() select i).ToList();
}
}
我有一个基于 XAML 的内容页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Todo.Views.DatePage">
<ListView x:Name="Listnotes">
<ListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Note}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
ListView的绑定是在C#中进行的:
NoteHelper nh = new NoteHelper();
private IEnumerable<Notes> notelist = new List<Notes>();
notelist = nh.GetItems((DateTimeOffset.Now));
Listnotes.ItemsSource = notelist;
当我在 Windows Phone 上构建解决方案时,我收到以下错误语句。我做错了什么?
System.NullReferenceException:对象引用未设置为对象的实例。
at Xamarin.Forms.Platform.WinRT.CellControl.SetCell(Object newContext)
at Xamarin.Forms.Platform.WinRT.CellControl.MeasureOverride(Size availableSize)
at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
at Xamarin.Forms.Platform.WinRT.VisualElementRenderer`2.MeasureOverride(Size availableSize)
at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
at Xamarin.Forms.Platform.WinRT.VisualElementR
【问题讨论】:
标签: c# xamarin xamarin.forms