如何将数据发送到通过 Silverlight 4 中的 Frame.Navigate 导航到的页面
平台:
Silverlight 4 / .NET 4
背景:
我有一个由两部分组成的页面。左边是树状视图,右边是内容区域。当我选择一个树项目时,根据树项目的类型,应在页面的右侧部分加载适当的 UserControl 页面。
我正在使用在 XAML 中定义的 Frame 对象。 当用户选择树视图项目时,我解析该项目的类型,然后导航到为该类型定义的页面。
但是,Frame.Navigate 是一种异步方法,因此如果我尝试在 Navigate 之后获取框架的内容,框架尚未导航,因此我要么什么也得不到,要么得到最后加载的页面。
contentFrame.Navigate(new Uri("/PageA.xaml", UriKind.Relative));
PageA page = contentFrame.Content as PageA;
// page here is either null or a previously opened page
问题:
我需要将一些数据(存储在树视图项的标签中)发送到正在导航到的页面,并且唯一的 Frame.Navigate 重载是异步的(没有回调)。 如何将一些数据发送到导航页面?还有其他技术可以实现我的需要吗?
Platform:
Silverlight 4 / .NET 4
Background:
I have a page that consists of two parts. The left part is a tree view, the right one is the content area. When I select a tree item, an appropriate UserControl page should be loaded in the right part of the page, depending on the type of the tree item.
I am using a Frame object, defined in XAML.
When a user selects a tree view item, I resolve the item's type and then I navigate to the page defined for that type.
However, Frame.Navigate is an asynchronous method so if I try to get the frame's content after Navigate, the frame has not navigated yet, so I either get nothing or the last loaded page.
contentFrame.Navigate(new Uri("/PageA.xaml", UriKind.Relative));
PageA page = contentFrame.Content as PageA;
// page here is either null or a previously opened page
Problem:
I need to send some data (stored in treeview item's Tag) to the page being navigated to and the only Frame.Navigate overload is asynchronous (without callback). How can I send some data to the navigated page? Is there any other technique for accomplishing what I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用Silverlight提供的NavigationService。它具有查询字符串支持,您可以使用它构建 RESTful URI。我假设您需要将一些基于上下文的数据传递到登录页面。以下链接可能会帮助您
http://www.silverlightshow.net/ items/The-Silverlight-3-Navigation-Framework.aspx
http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/04/02/silverlight-3-quick-tip-6-navigation-framework-and-uri-routing。 aspx
http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/07/silverlight-3-s-new-navigation-framework.aspx
虽然链接Silverlight 3 表示,Silverlight 4 也支持这些功能。
You can use the NavigationService provided by Silverlight. It has query string support using which you can build RESTful URI. I am assuming that you need to pass some context based data to the landing page. Following links might help you
http://www.silverlightshow.net/items/The-Silverlight-3-Navigation-Framework.aspx
http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/04/02/silverlight-3-quick-tip-6-navigation-framework-and-uri-routing.aspx
http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/07/silverlight-3-s-new-navigation-framework.aspx
Although the links says Silverlight 3, these features are supported in Silverlight 4 as well.
您肯定想使用 Nilesh 建议的某种 MV-VM 模式。
我想你也可以有一个静态类来保存对象的静态引用。
当您的框架完成其事件(例如 NavigatedTo)时,您可以简单地在此处引用静态对象。
You definitely want to use some flavor of the M-V-VM pattern that Nilesh suggested.
I guess you could also have a static class that holds static references of objects.
You can simply refer to static objects here when your frames have completed their event (e.g. NavigatedTo).