简体   繁体   English

Silverlight-在页面之间共享数据

[英]Silverlight - sharing data between pages

I'm trying to develop my first Silverlight navigation application. 我正在尝试开发我的第一个Silverlight导航应用程序。 This application has 2 main pages, "Data", and "Analysis". 该应用程序有2个主页,“数据”和“分析”。 The Data page is where the user can load in a csv file into a custom datatable object :-), whilst the Analysis page is where the user can analyse the datatable. 数据页时,用户可以在一个CSV文件加载到一个自定义的DataTable对象:-),而分析页面中,用户可以分析数据表。

How do I expose/share the datatable on the Data page so that the Analysis page can access it? 如何在“数据”页面上公开/共享数据表,以便“分析”页面可以访问它?

You can also create some class with public static field in it. 您还可以创建一个带有公共静态字段的类。 All these field would be accessible to all pages. 所有这些字段将可用于所有页面。 So they can be used as globals. 因此它们可以用作全局变量。 Something like that: 像这样:

public class DataClass
{
    public static DataTable DataTable1;
}

I'm pretty uncomfortable with you defining variables in the app class so that they are globally available and I absolutely can't (frankly) see using the disk as an intermediary. 我非常不高兴在应用程序类中定义变量,以便它们在全局范围内可用,而且我绝对(坦率地说)绝对看不到将磁盘用作中介。

I explore one way to solve this in this tutorial 我将在本教程中探索解决此问题的一种方法

In SL4 a cleaner way may be to use the Frame to hold a reference to a business object that can be passed among pages. 在SL4中,一种更简洁的方法可能是使用框架来保存对可在页面之间传递的业务对象的引用。 I'll explore that a bit and comment soon. 我将对此进行探讨,并尽快发表评论。

Thanks 谢谢

- Jesse Liberty - 杰西·自由Jesse Liberty)

使数据库成为应用程序资源或应用程序生存期对象。

将其保存到隔离的存储中,然后在“分析”页面上重新加载。

Well in the end I worked out that you could access the Application class at any point through 最后,我得出结论,您可以随时通过以下方式访问Application类

        App app = (App)Application.Current;

and then define your variables in the App class - simple! 然后在App类中定义变量-简单!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM