导航到 silverlight 中页面的现有实例

发布于 2024-10-20 10:18:04 字数 423 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜声 2024-10-27 10:18:04

你的问题看起来确实很混乱。

应该用 ContentControl 替换框架吗?

这意味着您没有充分的理由首先将框架放在那里,并且您没有使用导航框架。在这种情况下,您当然应该用其他东西替换 Frame

如果您可以用其他东西替换框架,则您的“页面”不需要是 Page 类型,它也可以是 UserControl

一切都可以归结为拥有这个简单的 Xaml:-

<Border x:Name="content" />

和这个 cs:-

UserControl p = ...; 
content.Child = p;

编辑

您需要保留框架,因此不能用 ContentControl 替换它。

您可以直接将 Page 分配给 Frame Content 属性。但是我不确定如果您单击后退按钮会发生什么。我怀疑它会导航到您替换的页面之前的页面。

另一种选择是我们使用静态服务将页面属性推送到堆栈上,然后页面可以在初始化时将它们从堆栈中弹出。这将允许您使用 Uri 导航到您的页面。

You question seems really quite confused.

should the frame rather be replaced by a ContentControl?

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 a UserControl.

It can all boil do down to have this simple Xaml:-

<Border x:Name="content" />

and this cs:-

UserControl p = ...; 
content.Child = p;

Edit:

You need to keep the frame therefore you can't replace it with a ContentControl.

You might just assign your Page directly to the Frame 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.

以往的大感动 2024-10-27 10:18:04

你面临的问题和我面临的问题是一样的。事件发生在框架之外,页面不知道该事件已发生,但需要将该事件通知给它。

现在可以做的是强制该框架内的页面刷新自身或通过以下方式处理这些事件: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文