【问题标题】:get listview value when click item in other page.xaml单击其他 page.xaml 中的项目时获取列表视图值
【发布时间】:2015-11-02 11:56:27
【问题描述】:

我有 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() 但我不知道我需要什么方法。)我想获得我点击的值。 (如果我点击第一个 -> 获得第一个,如果我点击第二个 -> 获得第二个值).....

【问题讨论】:

    标签: c# listview windows-phone-8.1


    【解决方案1】:

    您不需要将整个列表 item-source 传递给 hinoDetail 类。它(按名称)是一个详细信息类,无论如何都需要一个 hino 实例。

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

    然后在 hinoDetail 类中:

    hinos result = (e.Parameter as hinos);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多