使用Visual Studio Express 2010 for Windows Phone | C#| Silverlight的
假设我创建了一个名为Person的类,它有两个属性:name(string)和amount(int)。
List<Person> peopleList = new List<Person>();
我想创建一个Person列表,没有任何项目可以开始。用户将项目添加到该列表。但是,我无法从应用程序的不同页面访问此列表,因此可以在不同页面上的事件处理程序上添加Person的实例。此外,需要从另一页访问列表中的信息。有没有我可以创建列表的地方,以便可以全局访问?
或者我错过了关于列表和数据绑定的关键概念?
提前致谢。
答案 0 :(得分:0)
你没有遗漏任何东西(我希望;如果你是,我也很想念它!)。
我过去所做的是App.xaml.cs
:
public partial class App : Application
{
public List<Person> peopleList { get; set; }
public static App Instance { get {return (App) Application.Current;}}
....
然后,在您的应用程序中使用App.Instance.peopleList
访问您的数据。
该示例来自https://github.com/capnfabs/timecard-wp7/blob/master/App.xaml.cs