views:

74

answers:

3

I am building a Silverlight 3.0 app based on the Silverlight Navigation Application template. One road block I ran into is communicating between the Pages. For instance, I am in one Page, and I want to kick off another page and send it some data. I am at a loss as to how to do this.

Any ideas?

+1  A: 

Jesse Liberty has an excellent blog post about just this. I use the techniques described there myself in a multi page Silverlight application.

I'm not sure though whether you can apply this with the Silverlight Navigation Application template.

Ronald Wildenberg
It's a good blog post but it applies to Silverlight 2.
AngryHacker
+1  A: 

You have 2 options

  1. Use Publish/Subscribe pattern, i havent used this before, but it is useful in certain cases, i dont think it would solve ur problem though.
  2. Use Request parameters, basically when you navigate to the new view, call it like so

    NavigationService.Navigate(new Uri("/HomePage.xaml?HomePageId=12", UriKind.Relative));

You could slap some string.format in there to make it neater, but you get the idea, then on the new View, use string queryParam = HtmlPage.Document.QueryString["HomePageId"]; on page load to get the Id of the information you wish to display.

That should do it.

Neil
A: 

I've found an effective solution that does not involve too much complexity. I am using the LocalMessageSender and LocalMessageReceiver objects. The original purpose of these objects are to have 2 silverlight apps on the same web page talk to each, but it's just as good at having 2 views talk to each other.

The usage is really straight-forward. See this example for usage.

AngryHacker