Silverlight - sharing data between pages - silverlight

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?

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!

Related

Add class to c++ firemonkey project

I have written a small firemonkey mobile app in C++ XE6 using several forms/units which all attempt to read data from a json feed.
I would like to keep the user details in a separate class to pass in the REST request rather than pass them from form to form.
What is the syntax for creating a static class and, other than including a reference to myclass.h, how does one access it's properties please?

WPF Prism reloading module using IModuleManager.LoadModule

I need to display views in a Module.The Module Registers it's view using in Initialize method.
User will select module name from drop down list. First time it works using IModuleManager.LoadModule(string ModuleName). If I want to re-display the same module again(in the same region after clearing the previously displayed module) IModuleManager.LoadModule is not going to work. I dont know the views and regions contained in that Module. I know just ModuleName and I need to display it's view.
How can I do that?
Your questions is very confusing. Can you provide more information? The IRegionManager is the component to register Views to your predefined Regions. The ModuleManager is only responsible to load an assembly if I got that right.
I don't think you can Load a Module multiple times, because the second time it is loaded already. The logic for displaying views should be regulated via Services within your Modul so inside your Module should be a Method that uses the IRegionManager to register a specific View to a Region.
I don't know whether you use Unity or MEF ( or another IOC ) but you can obtain the IRegionManager within your Module via the Container.
Maybe you should watch this Tutorial series Prism Tutorial Series. It seems to me you are missing some basic principles

Silverlight with Frames and Pages: How to access the collection of references to already instantiated Pages?

My MainPage in Silverlight has one Frame, and inside it I can show the content of any of several Pages, navigating between them. All Pages have the NavigationCacheMode="Required" property assignment, so all of them are cached by the Navigation gear.
If the Navigation system caches the instance of every Page that I navigate to, that means that it stores those instances in some kind of list, or collection. How can I access that collection of references to already instantiated Pages?
My goal, simplified: Assuming that I have already navigated to Pages A and B, I want to access controls on Page B from Page A.
Thank you.
The cache required pages are maintained but the NavigationService in a private dictionary. No public access to the contents of the dictionary is provided.
If you really want to do this then you could manage this yourself with Load and Unload events of the pages being used to add/remove the pages instances in some public static dictionary.
However I would suggest that is not a good design pattern to have one page directly manipulate controls of another. Better would be to create a public static class through which the pages may communicate without actually being aware of each other.

asp.net mvc - extending the registration page (membership) versus new user table (profile) - are they the same thing?

I want to store additional information on my users (address, phone).
Should I extend the registration page on the sample mvc template or should I set up a separate "profile" table and have that be a separate page?
It seems nice to do it on the registration page, but I am not sure if there are issues playing around with the "aspnet_"... tables that are setup for registration.
Any suggestions? I would like to use LINQ to SQL as well if possible but I see the default implementation is using
System.Web.Security.membership
You could also consider creating custom Membership Provider.
In terms of usability, you always want your registration to be as short as possible. It's a good habit to get into, even if the application that you are currently developing is not a commercial application. So the best way to design the front end would be to have as little information required from the visitor for registration and then have a separate "profile" page once they are logged in after registration is successful.
In terms of database design, keeping the profile in a separate table is once again recommended.
Once you've done this, you can either treat the profile information as just another set of information that the user can edit OR you can implement ProfileProvider. All you need to do is implement GetPropertyValues and SetPropertyValues.
public class MyProfileProvider : ProfileProvider
{
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
}
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
}
}

How do I store some object globally?

I'm new to WPF and used to ASP.NET. I have a WPF app that will require a login screen. Throught the rest of the app I want to be able to access a "Session" object that will contain some credentials information. How do I store that so that any view in my app can access that object?
You can also use lightweight container to store objects globally in loosely coupled way and retrieve these object using Dependency Injection pattern.
One of implementations of lightweight container is Unity Application Block from Microsoft (http://www.codeplex.com/unity) so you can start there and read more here and here.
The Application object has a Properties property that allows you to store and retrieve application wide objects.
It is better explained here:
How to: Get and Set Application-Scope Properties
There are a few ways to do this.
You can create a static class, perhaps you might call it "Session" which holds the data that you are interested in. Session might have a Dictionary that contains the data that you are interested in.
You can hold the data in the main form, and have the main form pass a data container to each view.
There might be better ways to do this that are more compatible with your design goals if you can provide more details about the implementation and use cases.

Resources