我有一个 LongListSelector 填充了 List ,其中包含来自 SQLite 数据库的对象:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(DB_PATH);
var query = conn.Table<Prasanja>().Where(x => x.id == 3);
var result = await query.ToListAsync();
foreach (var item in result)
{
var query1 = conn.Table<Odgovori>()
.Where(y => y.Prasanja_id == item.id);
txtPrasanje.Text = item.Tekst;
var resultOdgovori = await query1.ToListAsync();
foreach (var itemOdgovor in resultOdgovori)
{
Lista.Add(itemOdgovor.Odgovor.ToString());
lstOdgovori.ItemsSource = Lista;
}
}
我想要的是当一个 LongListSelector 项目被点击时,我得到了特定的对象,并且能够使用该对象的属性。这是我的代码:
private void lstOdgovori_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector selector = sender as LongListSelector;
if (selector == null)
return;
Odgovori odg = selector.SelectedItem as Odgovori;
if (odg == null)
return;
if(odg.Tocno==null)
MessageBox.Show("Try again");
else MessageBox.Show("True!!!");
}
这里的问题是我的 Odgovori 类中的对象odg在执行此代码后返回 null。我怎样才能解决这个问题?