views:

66

answers:

1

Hi,

I am playing around with the WP7 SDK and the Prism for WP7 beta and have come across a problem I can't figure out (or even a workaround for).

First of all, I'm new into WPF/Silverlight/WP7 and Prism, so I could be overlooking something very obvious.

So I have a Shell page that has my region that is used to hold my content pages, and all of this is working great! Now my problem is that I have a settings control that will allow the users to edit the settings of the application (names, locations, etc). Now I can get this page to work with no problems by having a button on one of my controls that will transition the region manager to the control.

However, I would like to use the application bar on the phone to have the button, but I cannot for the life of me figure out how to get access to my model object from within the page that is opened by the Application bar click. I can only do a NavigationService.Navigate() to a settings page, but the PhoneApplicationPage objects in WP7 do not allow injection on the constructors (the constructors must be parameterless) so I cannot pass in the object instance in that way.

So my question is, how can I access (or pass) objects between pages or controls?

Thanks!

+1  A: 

In the examples they use this technique to set the data context of a form after it is navigated to from another form:

NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
root.DataContext = some_object;
robperson
Perfect! It's definately uglier than I would like, but it does the job.
doobist
Btw, I'd either use "FrameworkElement root = (FrameworkElement)Application.Current.RootVisual;" or check root for null.
Sam