我試圖從Linq創建單個選擇列表框,但是,我遇到了問題,設置每個列表框項目的id值與相應的ID保存在一個本地數據庫。我有以下代碼:在Windows Mobile 7中設置ListBoxItem的id值
public void display_Tips()
{
//commented out to try MrMDavidson's approach.
// listBoxTipHistory.Items.Clear();
// IList<Tips> tips = this.get_Tips();
// foreach (Tips tip in tips)
// {
// ListBoxItem li1 = new ListBoxItem();
// li1.Content = tip.date.Day + "-" + tip.date.Month + "-" +
// tip.date.Year + "-" + tip.date.Hour + ":" +
// tip.date.Minute + " - " + tip.resturant + " - $" +
// tip.tip_amount + " - $" + tip.billTotal;
// listBoxTipHistory.Items.Add(li1);
// }
if (listBoxTipHistory.Items.Count > 0)
{
listBoxTipHistory.Items.Clear();
}
listBoxTipHistory.ItemsSource = get_Tips();
}
public IList<Tips> get_Tips()
{
IList<Tips> tips = null;
using (TipContext context = new TipContext(conString))
{
IQueryable<Tips> query =
(from c in context.TipTable
orderby c.date descending
select c);
tips = query.ToList();
}
return tips;
}
表對於本地數據庫:
[Table]
public class Tips
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int tip_ID
{
get;
set;
}
[Column(CanBeNull = false)]
public float tip_amount
{
get;
set;
}
[Column]
public string resturant
{
get;
set;
}
[Column(CanBeNull = false)]
public DateTime date
{
get;
set;
}
}
XAML代碼:
<ListBox SelectionChanged="showTipDetails" x:Name="listBoxTipHistory" Margin="6,3,0,0">
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding resturant}" />
<TextBlock Text="{Binding date}" />
<TextBlock Text="{Binding tip_amount}" />
</StackPanel>
</DataTemplate>
</ListBox >
現在我試圖重新編碼與MrMDavidson的建議的工作,但是,使用這個當前的代碼,它會在列表中顯示「AppName.Tips」而不是實際的列數據。我已經嘗試了谷歌搜索演示和教程,但是,我一直無法提出解決方案。
此外,是否有一種特殊的方式來處理日期和時間?
任何建議,將不勝感激。
http://forums.asp.net/t/1468638.aspx/1 –