将选定的项目列表传递给xaml

我用C#编写了很新的代码,我用Laravel(php)编写了一个后台编码。

我需要使用CRUD构build应用程序(Windows 8.1)。 但在编辑我有一个问题, 我需要知道如何将选定的项目传递到其他xaml文件。

我需要将选定的MainPage项目传递给Editar

MainPage.xaml.cs中


    命名空间SQLiteDemo
     {
         /// 
         ///一个空的页面,可以单独使用或导航到Frame内。
         /// 
        公开密封的部分类MainPage:页
         {
             SQLiteAsyncConnection conn = new SQLiteAsyncConnection(“dados.sqlite”);

             public MainPage()
             {
                 this.InitializeComponent();
                 conn.CreateTableAsync();
             }

             private async void Listar_Click(object sender,RoutedEventArgs e)
             {
                等待Atualiza();
             }

            私人asynchronous任务Atualiza()
             {
                 var query = conn.Table();
                 listBox.ItemsSource =等待query.ToListAsync();
             }

             private void Novo_Click(object sender,RoutedEventArgs e)
             {
                 Frame.Navigate(typeof运算(Novo)中);
             }

             private void Editar_Click(object sender,RoutedEventArgs e)
             {
                 / *
                 var u = listBox.SelectedItem as User;
                 u.nome =“nome alterado”;
                等待conn.UpdateAsync(u);
                等待Atualiza();
                 * /
                 listBox.SelectedItems.Add(listBox.SelectedItem as User);
                 var u = listBox.SelectedItem as User;
                 Frame.Navigate(typeof(SQLiteDemo.Editar),u);
             }
         }
     }

Editar.xaml

<Grid HorizontalAlignment="Left" Height="520" Margin="55,115,0,0" VerticalAlignment="Top" Width="1155"> <TextBox x:Name="Nome" HorizontalAlignment="Left" Margin="70,60,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="40" Width="990" PlaceholderText="Nome"/> <TextBox x:Name="Email" HorizontalAlignment="Left" Margin="70,140,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="40" Width="990" PlaceholderText="Email"/> </Grid> 

Editar.xaml.cs

 namespace SQLiteDemo { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> /// public sealed partial class Editar : Page { SQLiteAsyncConnection conn = new SQLiteAsyncConnection("dados.sqlite"); public Editar() { this.InitializeComponent(); conn.CreateTableAsync<User>(); } private void SalvarEdit_Click(object sender, RoutedEventArgs e) { /* var u = listBox.SelectedItem as User; u.nome = Nome.Text; u.email = Email.Text; conn.UpdateAsync(u); */ } private void Voltar_Click(object sender, RoutedEventArgs e) { Frame.Navigate(typeof(MainPage)); } } } 

一些截图:

主页 在这里输入图像说明

编辑页面 在这里输入图像说明

你传递参数的权利剩下的只是在导航后得到它。

将此函数添加到Editar.xaml.cs

 protected override void OnNavigatedTo(NavigationEventArgs e) { var user = e.Parameter as User; Nome.Text = user.nome; Email.Text = user.email; }