我想做一个测试,首先重定向到空白页然后重定向到正常页面,但看起来它没有进行第二次重定向......
Browser.Base = Constants.ParkInfoDirectory; // "ParkInfo" folder
string s = string.Format("{0}/section_{1}.html", _parkId, _parkPage);
// URL = "/ParkInfo/ti217/5" for page 5 of Rainier
string blank = string.Format("{0}/Blank.html", _parkId);
Browser.Navigate(new Uri(blank, UriKind.Relative));
this.Browser.UpdateLayout();
Browser.Navigate(new Uri(s, UriKind.Relative));
this.Browser.UpdateLayout();
新版本:
string s = string.Format("{0}/section_{1}.html", _parkId, _parkPage); // URL = "/ParkInfo/ti217/5" for page 5 of Rainier
string blank = string.Format("{0}/section_blank.html", _parkId);
Uri blank_ = new Uri(blank, UriKind.Relative);
Browser.Navigate(new Uri(blank, UriKind.Relative));
Browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(Browser_Navigated);
{
if (e.Uri == blank_)
{
Browser.Navigate(new Uri(s, UriKind.Relative));
}
};
Browser.Navigate(blank_);
答案 0 :(得分:2)
您在一次UI thread
执行中调用两个导航方法。它可能会导致一些问题。尝试在Navigate
内添加第二个Dispatcher
以延迟执行或订阅Navigated
事件并从中调用第二个Navigate
Browser.Navigate(new Uri(blank, UriKind.Relative));
Dispatcher.BeginInvoke(() =>
{
Browser.Navigate(new Uri(s, UriKind.Relative));
});
或者:
Uri blank_ = new Uri(blank, UriKind.Relative)
Browser.Navigated += (s, e) =>
{
if (e.Uri == blank_)
{
Browser.Navigate(new Uri(s, UriKind.Relative));
}
};
Browser.Navigate(blank_);