Silverlight - sharing data between pages
I'm trying to develop my first Silverlight navigation application. This application has 2 main pages, "Data", and "Analysis". 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开发者_Go百科 the 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. I'll explore that a bit and comment soon.
Thanks
-Jesse Liberty
Make the database an Application Resource or Application Lifetime Object.
Save it into isolated storage and reload it on the Analysis page.
Well in the end I worked out that you could access the Application class at any point through
App app = (App)Application.Current;
and then define your variables in the App class - simple!
精彩评论