将列表框数据从一页传递到另一页 [英] Passing listbox data from one page to another

查看:87
本文介绍了将列表框数据从一页传递到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将列表框数据从一页传递到另一页时遇到麻烦.

I was having trouble passing listbox data from one page to another.

我创建了一个具有变量的GlobalVariables类:

I created a GlobalVariables class that has the variable:

public static ListBox lister = new ListBox();

然后,我使用for循环将Mainbox中列表框中的数据存储到全局列表框中:

I then store the data from my listbox in my MainPage into the global listbox by using a for loop:

for(int i = 0; i < listofbananas.Items.Count; i++)
{
GlobalVariables.lister.Items.Add(listofbananas.Items[i]);
}

在Page2.xaml中,我使用for循环将数据从全局列表框转移到Page2的列表框:

In Page2.xaml I transfter the data from the global listbox to Page2's listbox by using a for loop:

for (int i = 0; i < GlobalVariables.lister.Items.Count; i++)
{
    listofgrapes.Items.Add(GlobalVariables.lister.Items[i]);
}

但是我得到一个" 元素已经是另一个元素的子代"了.错误.

But im getting a "Element is already the child of another element" error.

我该如何解决?使列表框可被其他页面访问的最简单方法是什么?

How do i fix this? Whats the easiest method to make a listbox accessible to other pages?



推荐答案

嗨singh029,

Hi singh029,

您可以执行以下操作:

页面之间的参数

希望它会有所帮助.


这篇关于将列表框数据从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆