tags:

views:

84

answers:

3

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?

+1  A: 

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

gcores
+1  A: 

There are a few ways to do this.

  1. 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.

  2. 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.

MedicineMan
+1  A: 

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.

jarek