wptoolkit windows phone 8 AutocompleteBox

本文关键字:AutocompleteBox phone windows wptoolkit | 更新日期: 2023-09-27 18:04:57

我能够将autocompletebox连接到隔离存储中的本地数据库,并且它可以工作。我在尝试使用选择更改事件获取所选项目时卡住了。这是我的类

[Table]
public class Hymns
{
    [Column(IsPrimaryKey=true, IsDbGenerated=true, DbType="INT NOT NULL Identity", CanBeNull=false, AutoSync=AutoSync.OnInsert)]
    public int hymnId { get; set; }
    [Column]
    public string Title { get; set; }
    [Column]
    public string Number { get; set; }
    [Column]
    public string Audio { get; set; }
    [Column]
    public string Stanza { get; set; }
    [Column]
    public bool IsFavorite { get; set; }
} 

我试过这个代码:

 private void acBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
        {
            MessageBox.Show(e.AddedItems[0].ToString());
        }
    }

我仍然没有得到一个值。我想要得到hymnId属性。有人能帮我吗?

wptoolkit windows phone 8 AutocompleteBox

尝试将AddedItems[0]转换为Hymns,例如:

MessageBox.Show(((Hymns)e.AddedItems[0]).hymnId);

…或者为了可读性分成几行:

Hymne selectedHymne = (Hymns)e.AddedItems[0];
MessageBox.Show(selectedHymne.hymnId);

谢谢你的回答。我使用选择改变事件处理程序来找出它

private void acBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                ItemViewModel firstItem = e.AddedItems[0] as ItemViewModel;
                if (firstItem != null)
                {
                    int fileId = firstItem.HymnId;
                    fileId = fileId - 1;
                    NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + fileId, UriKind.Relative));
                }
            }
        }