数据绑定 SQLIte 到 Listbox(包含三个控件)Windows phone 8
Data Binding SQLIte to Listbox(containing three controls) Windows phone 8
我是实施 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;
}
我的任务class
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”(在列表框位置.. 不在数据控件中模板)..它只是返回方法放置在 class 任务中..请告诉我如何将数据绑定到放置在 lsitbox 中的控件。
我已经在 stack over flow 中关注了很多类似的问题,..
Slect data from SQLite
bind data to list box
bind data dynamically
请将列表框和列表框内的控件的高度和宽度保持在 "Auto" 在 xaml.if 您使用了任何边框控件..确保宽度和高度设置为 "Auto"
Height="Auto" Width="Auto"
请检查并返回错误图片..
我是实施 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;
}
我的任务class
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”(在列表框位置.. 不在数据控件中模板)..它只是返回方法放置在 class 任务中..请告诉我如何将数据绑定到放置在 lsitbox 中的控件。 我已经在 stack over flow 中关注了很多类似的问题,..
Slect data from SQLite
bind data to list box
bind data dynamically
请将列表框和列表框内的控件的高度和宽度保持在 "Auto" 在 xaml.if 您使用了任何边框控件..确保宽度和高度设置为 "Auto"
Height="Auto" Width="Auto"
请检查并返回错误图片..