English 中文(简体)
How to communicate between the Views in the Silverlight 3.0 application?
原标题:

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?

最佳回答

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.

问题回答

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.

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.





相关问题
combining flipsideview and navigationview

when i am trying to combine flipsideview and navigation view i am getting following error "request for member delegate is something not in a structure or union" on the line controller.delegate = ...

Rails category navigation with tags

I want to create a navigation system for my web application where there are several main categories for articles and several sub tags for each category. For example, in category "Writing" there might ...

Wordpress Navigation

I am working on a Wordpress Theme, I need to work on the navigation, I am having a little trouble creating it. The navigation I am looking for looks like this: www.neu.edu/humanities. I have gotten ...

Silverlight cant find page error

I have started a a new project (to refactor some code), and just can t work out why I keep getting "Can t find page /Index" error. The code works fine until I use an add method (on any collection ...

Zend Framework - multiplate navigation blocks

I want to use the navigation helper to build my navigation menus using Acl. The Acl part I have working fine. I now want to be able to display a few different types of navigation. E.g. admin-nav, ...

Creating a Web Navigation Helper Class for MVC

Im a newbie to MVC and trying to use the web navigator class in my MVC application. http://polymorphicpodcast.com/shows/webnavigator/ The class enables us to have stongly typed urls in a central class ...

热门标签