在 Silverlight 中设置 HtmlPage.Window.CurrentBookmark 属性时禁止导航

发布于 2024-10-30 13:42:40 字数 703 浏览 0 评论 0原文

我有一个场景,我需要更改 HtmlPage.Window.CurrentBookmark 属性,但我想在不导致 Silverlight 应用程序重新加载的情况下执行此操作。现在,我正在这样做,但它导致应用程序重新启动:

public void SetBookmark(string authenticationGroupTag, string ownerUserTag, string roomName)
{
    string bookmark = GetBookmark(authenticationGroupTag, ownerUserTag, roomName);
    HtmlPage.Window.CurrentBookmark = bookmark;
    // HtmlPage.Window.Eval("window.location.hash='" + bookmark + "'");
}

这种特定行为(重新启动应用程序)似乎没有在任何地方记录,所以我想知道我是否只是做错了。我尝试捕获各种与导航相关的事件(Page.OnNavigateFrom 或 RootFrame.Navigating),但这些事件实际上都没有被触发:应用程序只是卸载然后重新加载。

所以我想我的问题有两个部分:(1)这是预期的行为,还是我只是做错了什么? (2) 如果这是预期的行为,是否有人想出解决方法?有没有办法在不重新加载 Silverlight 应用程序的情况下更新“#”之后的 URL 部分?

I have a scenario where I need to change the HtmlPage.Window.CurrentBookmark property, but I want to do it without causing the Silverlight application to reload. Right now, I'm doing this, but it's causing the application to restart:

public void SetBookmark(string authenticationGroupTag, string ownerUserTag, string roomName)
{
    string bookmark = GetBookmark(authenticationGroupTag, ownerUserTag, roomName);
    HtmlPage.Window.CurrentBookmark = bookmark;
    // HtmlPage.Window.Eval("window.location.hash='" + bookmark + "'");
}

That particular behavior -- restarting the application -- doesn't seem to be documented anywhere, so I wonder if I'm just doing it wrong. I've tried catching various navigation related events (either Page.OnNavigatedFrom or RootFrame.Navigating), but neither of those actually get fired: the app just unloads and then reloads.

So I guess I have two parts to my question: (1) Is this the expected behavior, or am I just doing something wrong? and (2) If it is the expected behavior, has anyone come up with a workaround for it? Is there a way to update the portion of the URL after the "#" without reloading the Silverlight application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

半城柳色半声笛 2024-11-06 13:42:40

事实证明,这只是一个长期被注意到的问题的变体,即当 (a) 用户在重定向后到达当前页面,以及 (b) 您更改 window.location 时,Internet Explorer 会刷新页面.hash。换句话说,这是一个 IE 问题(在 IE9 中仍然没有修复!),而不是 Silverlight 问题。 Firefox 和 Chrome 一切正常。 (请参阅 在 IE 中刷新 javascript location.hash带有片段标识符的Response.Redirect在稍后使用location.hash时会导致意外刷新 了解更多详细信息和一些建议的解决方法。)

Turns out that this is just a variant of a problem that's been long noted, namely, that Internet Explorer refreshes the page when (a) the user has arrived at the current page after a redirect, and (b) you change the window.location.hash. In other words, this is an IE issue (still not fixed in IE9!), not a Silverlight problem. Everything behaves correctly with Firefox and Chrome. (See javascript location.hash refreshing in IE and Response.Redirect with a fragment identifier causes unexpected refresh when later using location.hash for more details, and some suggested workarounds.)

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