views:

159

answers:

5

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 the datatable.

How do I expose/share the datatable on the Data page so that the Analysis page can access it?

A: 

Make the database an Application Resource or Application Lifetime Object.

Michael S. Scherotter
It's got nothing to do with databases - there are no databases in the app. The user loads in a csv file on the Data page which could be anything so I don't understand how we can make it static?
Calanus
A: 

Save it into isolated storage and reload it on the Analysis page.

mattb
I guess that would be an option but seems like overkill to serialise/deserialise something to disk when you could store it in memory
Calanus
This is where I start to get confused being a bit new to Silverlight. I haven't been able to find good documentation that explains how to deal with objects from page to page. In fact, the documentation and examples for Silverlight seem to be lacking all the way around. Almost all of it is reference and most blogs I've found are all just re-showing the very simple examples found in the docs. The best thing I could come up with for this type of scenario is isolated storage.
mattb
I'll look into the suggestion for App variables. At first glance it feels like the global.asax vibe which seems to be overkill for a situation like this. I agree that serializing would be overkill, too.If someone has a link to documentation that shows an end to end biz application please post it. I've looked at the prism example (stock trader) and it's great in some respects but it's extremely complex and mostly deals with modularity in the UI.
mattb
I've also looked at the other stock trader example and.. well, that's an amazing application but it's waaay too much for someone trying to grasp the basics of building an application in Silverlight.
mattb
A: 

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!

Calanus
+1  A: 

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

Jesse Liberty
I've had a look at the link and it is all interesting stuff. I understand the concerns about what are effectively global variables in the App class and I'm sure that Uncle Bob would beat me for it, but the alternative in the link seems a lot of code + added complexity over a couple of lines in the App class!
Calanus
I'll look forwards to seeing the SL4 method though...
Calanus
+1  A: 

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;
}
Fedor
Yes this does seem a fairly good way of doing it and also would keep the app class clean
Calanus