导航到 silverlight 中页面的现有实例
在 silverlight 的 Frame
上,我希望能够导航到 Page
的现有实例。简而言之,这就是我想要的:
Page p = ...; // initialize the page and set some of the properties
contentframe.Navigate(p);
而不是使用创建页面的 Uri。
这可以实现吗(如在 WPF 中),还是应该用 ContentControl
替换框架?
编辑:更清楚:有没有一种方法可以在 silverlight 中模拟 WPF 中可用的 NavigationService.Navigate(object root)
?
On a Frame
in silverlight I want to be able to navigate to an existing instance of a Page
. In short this is what I want:
Page p = ...; // initialize the page and set some of the properties
contentframe.Navigate(p);
Instead of using an Uri from which the page is created.
Can this be achieved (as in WPF), or should the frame rather be replaced by a ContentControl
?
Edit: More clarity: Is there a way that NavigationService.Navigate(object root)
that is available in WPF can be simulated in silverlight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题看起来确实很混乱。
这意味着您没有充分的理由首先将框架放在那里,并且您没有使用导航框架。在这种情况下,您当然应该用其他东西替换
Frame
。如果您可以用其他东西替换框架,则您的“页面”不需要是
Page
类型,它也可以是UserControl
。一切都可以归结为拥有这个简单的 Xaml:-
和这个 cs:-
编辑:
您需要保留框架,因此不能用 ContentControl 替换它。
您可以直接将
Page
分配给Frame
Content
属性。但是我不确定如果您单击后退按钮会发生什么。我怀疑它会导航到您替换的页面之前的页面。另一种选择是我们使用静态服务将页面属性推送到堆栈上,然后页面可以在初始化时将它们从堆栈中弹出。这将允许您使用 Uri 导航到您的页面。
You question seems really quite confused.
That would imply that you don't have good reason to have the frame there in the first place and you aren't using a navigating framework. In which case certainly you should replace the
Frame
with something else.If you can replace the frame with something else the there is no need for your "Page" to be of type
Page
, it may as well be aUserControl
.It can all boil do down to have this simple Xaml:-
and this cs:-
Edit:
You need to keep the frame therefore you can't replace it with a ContentControl.
You might just assign your
Page
directly to theFrame
Content
property. However I'm not sure what would happen if you then click the back button. I suspect it would navigate to the page prior to the page you replaced.Another option would be to us a static service to push your page properties on to a stack, you page can then pop them off this stack when initialising. This would allow you to navigate using a Uri to your page.
你面临的问题和我面临的问题是一样的。事件发生在框架之外,页面不知道该事件已发生,但需要将该事件通知给它。
现在可以做的是强制该框架内的页面刷新自身或通过以下方式处理这些事件:1:临时存储页面的状态,b)通过查询字符串传递“命令”。
The problem you are facing is the same problem that I am facing. An event happens outside the frame, and the page has no idea that the event has ocured, but it needs to be notified of that event.
Now what can be done is force the page within that frame to refresh itself or handle those events by 1: storing the page's state temporarily, and b) passing "commands" through the query string.