Silverlight 3.0应用程序中的View之间如何通信?
我正在基于 Silverlight 导航应用程序模板构建 Silverlight 3.0 应用程序。我遇到的一个障碍是页面之间的通信。例如,我在一个页面中,我想启动另一个页面并向其发送一些数据。我不知道如何做到这一点。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有 2 个选项
使用请求参数,基本上当你导航到新视图时,像这样调用它
NavigationService.Navigate(new Uri("/HomePage.xaml?HomePageId=12", UriKind.Relative));
您可以在其中添加一些 string.format 以使其更整洁,但您明白了,然后在新视图上,在页面上使用
string queryParam = HtmlPage.Document.QueryString["HomePageId"];
load 获取您要显示的信息的 Id。应该可以做到这一点。
You have 2 options
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.
我找到了一个有效的解决方案,并且不涉及太多复杂性。我正在使用 LocalMessageSender 和 LocalMessageReceiver 对象。这些对象的最初目的是让同一网页上的 2 个 silverlight 应用程序相互通信,但它也同样适合让 2 个视图相互通信。
用法非常简单。请参阅此 使用示例。
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.
Jesse Liberty 有一篇出色的博客文章,内容仅涉及这。我自己在多页 Silverlight 应用程序中使用了其中描述的技术。
我不确定您是否可以将其与 Silverlight 导航应用程序模板一起应用。
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.