M Kenyon II
M Kenyon II

Reputation: 4264

Pass data/object between assemblies in WP7

The Windows Phone 7 project I'm working on has 2 UIs, and a core 'engine' of functionality with some pages that are common. I'd like my user interface to pass an object into one of these common pages in the core assembly.

Currently I can navigate to pages in the core assembly from the UI assembly. However, it is my understanding that each assembly has it's own Isolated storage, is that correct?

If I can share Isolated storage, I can use that, I'm just not sure how to get the two assemblies to use it together.

What's the best practice?

I tried googling this: 'wp7 pass object between assemblies'

More Info:
This would be 1 application with two assemblies. Something like this:

CustomerUI (project)
- MainPage.xaml
- App.xaml

CoreFuncs (project)
- CustomerData.cs
- EditCustomer.xaml

SalesRepUI (project)
- MainPage.xaml
- App.xaml

Both CustomerUI and SalesRepUI would use the EditCustomer page and customerData object. So, from MainPage a CustomerData object is instantiated, then a user could click 'Edit User' which would navigate to the common EditCustomer.xaml page. We would want to pass in the already instantiated CustomerData object. (For the purpose of this discussion...)

Upvotes: 1

Views: 456

Answers (4)

M Kenyon II
M Kenyon II

Reputation: 4264

Sorry, Sorry, I found what I wanted, I was thinking too hard. PhoneApplicationService.Current.State["keyName"] = object; was exactly what I wanted. Not sure if its the best way, but for me, it works. Just throw my settings class or whatever in there, and catch it on the other side in the page.xaml code.

Upvotes: 1

James Cadd
James Cadd

Reputation: 12216

I would recommend using the Messenger class in the MVVM Light toolkit: http://blog.galasoft.ch/archive/2009/09/27/mvvm-light-toolkit-messenger-v2-beta.aspx

Both of your assemblies can reference a single shared assembly; that assembly can contain a type that you use to hold data passed via the messenger.

Upvotes: 0

JonAlb
JonAlb

Reputation: 1720

It depends are these two separate applications or two assemblies?

Isolated storage is isolated around the running application. This means each app has its own storage that cannot be accessed from a different app. The only ways to share data between two apps are:

  1. A WebService/or TCP service in 7.5: You would upload the data from one app and download the data into a separate application.

  2. User performed tasks: Copy and Paste/Sending an Email

However if this is just one application you will be able to access the isolated storage between the assemblies just by reading and writing to the files. The only thing to be aware of is file locking, make sure you close files any before you attempt to read from them from a separate dll/assembly.

Upvotes: 1

Ku6opr
Ku6opr

Reputation: 8126

As I know, there is one Isolated storage per application, not per assembly. So you can try pass your objects through it if you like.

Upvotes: 1

Related Questions