【发布时间】:2015-08-22 11:53:39
【问题描述】:
我是实施 SQLITE DB 和 windows phone 8 应用程序开发的新手...
实现了以下 startegy 将数据检索到包含其他三个控件的列表框..
这是我的 XAML 代码..
<ListBox Height="Auto" Name="TaskListBox" Margin="5,61,-1,298">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Red" Height="480" Width="200">
<TextBlock Text="{Binding status }" Name="team1Name" Width="120" ></TextBlock>
<TextBlock Text="{Binding CreationDate }" Name="team3Name" Foreground="White" Width="120" HorizontalAlignment="Center"></TextBlock>
<HyperlinkButton Content="{Binding Merid_FK }" Name="team2Name" Foreground="White"/>
<TextBlock Text="{Binding status}" Name="venue" Foreground="White" Height="67" Width="78"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
还有我的代码
private void Insert_Click(object sender, RoutedEventArgs e)
{
using (var db = new SQLiteConnection(DB_PATH))
{
db.RunInTransaction(() =>
{
db.Insert(new tasks() { Merid_FK = 126745, status = "Y", CreationDate = DateTime.Now });
db.Insert(new tasks() { Merid_FK = 1289906, status = "N", CreationDate = DateTime.Now });
});
}
private void Retrieve_Click(object sender, RoutedEventArgs e)
{
List<tasks> listmerchant = dbConn.Query<tasks>("SELECT * from tasks where status='" + "Y" + "'").ToList<tasks>();
TaskListBox.ItemsSource = listmerchant;
}
我的任务类
public sealed class tasks
{
//[PrimaryKey,AutoIncrement]
public int Merid_FK { set; get; }
public string status { set; get; }
public DateTime CreationDate { set; get; }
public override string ToString()
{
return Merid_FK + ">> " + status + ">> " + CreationDate.ToShortDateString() ;
}
}
我的问题是,我在 UI 上获得输出为“16757 >> status1 >> 2012-12-20 12:20”(在列表框位置.. 不在数据模板中的控件处).. 它只是返回方法放置在课堂任务中。请告诉我如何将数据绑定到放置在 lsitbox 内的控件。 我已经在 stack over flow 中关注了很多类似的问题,..
【问题讨论】:
-
看起来您实际上并没有得到返回的任务对象。您应该通过创建一些硬编码的任务对象来测试它并查看它们是否呈现。如果他们这样做了,那么您就会知道查询没有返回正确的信息。我认为问题在于您只选择状态而不是对象的其他成员。
标签: c# .net sqlite xaml windows-phone-8