2015-11-02 58 views
0

我有类列表视图,列表视图是从源码得到的ListView值时,在其他page.xaml点击项目

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)); 
    } 

的hinoDet所有的类只是从listview中获取第一个值,因为(FirstOrDefault()但我不知道我需要什么方法。),我想获得我点击的值。 (如果我在第一次点击 - >获得第一,如果我在第二次 - >获得第二个值).....

回答

0

您不需要将整个列表item-source传递给hinoDetail类。它是(通过名字)一个细节类,在任何情况下都需要一个hino实例。

Frame.Navigate(typeof(hinoDetail),listaHinos.SelectedItem); 

然后在hinoDetail类:

hinos result = (e.Parameter as hinos);