在 Silverlight 中设置 HtmlPage.Window.CurrentBookmark 属性时禁止导航 [英] Suppress navigation when setting HtmlPage.Window.CurrentBookmark property in Silverlight

查看:63
本文介绍了在 Silverlight 中设置 HtmlPage.Window.CurrentBookmark 属性时禁止导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 + "'");
}

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

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.

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

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?

推荐答案

事实证明,这只是长期以来一直被关注的问题的一个变体,即 Internet Explorer 在 (a) 用户到达时刷新页面重定向后的当前页面,以及 (b) 您更改 window.location.hash.换句话说,这是一个 IE 问题(在 IE9 中仍未修复!),而不是 Silverlight 问题.在 Firefox 和 Chrome 中一切正常.(参见 IE 中的 javascript location.hash 刷新Response.Redirect with a fragment identifier 稍后使用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.)

这篇关于在 Silverlight 中设置 HtmlPage.Window.CurrentBookmark 属性时禁止导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆