我有listview的类,listview从sqlite获取值
public Lista()
{
this.InitializeComponent();
carregaLista();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Home));
}
public async void carregaLista()
{
var local = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "hinos.sqlite");
SQLiteAsyncConnection con = new SQLiteAsyncConnection(local, SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite);
listaHinos.ItemsSource = await con.Table<hinos>().ToListAsync();
}
public void listaHinos_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Frame.Navigate(typeof(hinoDetail),listaHinos.ItemsSource); // passing listview to hinoDetail Class
}
我将列表视图传递给
下面的hinoDetail类
public hinoDetail()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// List<hinos> result = e.Parameter as List<hinos>;
hinos result = (e.Parameter as List<hinos>).FirstOrDefault(); // get first line only
nomeHinoDetail.Text = result.numHino + " " + result.nomeHino;
textBlock.Text = result.letraHino;
}
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(Lista));
}
hinoDetail类只获取listview中的第一个值,因为(FirstOrDefault()但我不知道我需要什么方法。)我想得到我点击的值。 (如果我点击第1个 - &gt;获得第1个,如果我在第2个点击 - &gt;获得第2个值).....
答案 0 :(得分:0)
您无需将整个列表项源传递给hinoDetail类。它(按名称)是一个细节类,在任何情况下都需要一个hino实例。
Frame.Navigate(typeof(hinoDetail),listaHinos.SelectedItem);
然后在hinoDetail类中:
hinos result = (e.Parameter as hinos);