我想弄清楚如果一个oauth页面已加载。wp7 c#LoadCompleted没有射击
所以我让我的网页浏览器导航到:
"https://api.munzee.com/oauth?response_type=code&client_id=" + API.ClientID + "&redirect_uri=" + API.RedirectUri;
其重定向率先 “https://api.munzee.com/oauth/signin” 显示一个简单的公式推这样的:
<html>
<body>
<img src='https://static-cdn-munzee.netdna-ssl.com/images/munzee-logo.svg' style='width: 160px;'/>
<p>
The application <strong>my WP7 App</strong> would like to access your munzee.com player account.<br/>
This application won't be able to access or store your login credentials in any way.<br/>
Authorization for this application can be revoked at any time by visiting <a href='http://www.munzee.com/revoke'>http://www.munzee.com/revoke</a>.
</p>
<p><strong>Please sign in:</strong></p>
<form method='POST'>
<p>Username:<br/><input type='text' name='username'/></p>
<p>Password:<br/><input type='password' name='password'/></p>
<p><input type='submit' value='Login'/></p>
</form>
</body>
</html>
但LoadCompleted事件不火,一旦文件加载(我可以看到页面成功加载在浏览器中)。该导航事件触发就好了......
这里是我到目前为止的代码:
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
BackGroundBrowser.Navigate(
new Uri("https://api.munzee.com/oauth?response_type=code&client_id=" +
API.ClientID + "&redirect_uri=" + API.RedirectUri, UriKind.Absolute)
);
}
private void BackGroundBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("BackGroundBrowser_LoadCompleted: " + BackGroundBrowser.Source.ToString());
// do some smart things...
}
private void BackGroundBrowser_Loaded(object sender, RoutedEventArgs e)
{
BackGroundBrowser.Navigate(new Uri("about:blank", UriKind.Absolute));
}
private void BackGroundBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("BackGroundBrowser_Navigated: " + BackGroundBrowser.Source.ToString());
}
如果你有兴趣这个主题,让我知道,我会为你提供我的clientID的和redirectUri为测试目的。但我不想让这些信息公开。
为什么会发生这种情况,是否有方法可以确定页面是否已加载?我现在唯一的想法是在“导航”处理程序中创建一个循环,检查一些与页面相关的值,并在条件匹配时手动触发事件。
但是,这似乎有点模糊,因为这个页面可以改变,我不想每次他们更新应用程序,例如,改变一些风格...
http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.loadcompleted(v=vs.95).aspx “顶级导航时出现财产来源被调用 如果发生错误,例如无法找到内容,则当从Web服务器返回错误时,会引发LoadCompleted事件...有关处理事件的更多信息,请参阅事件概述Silverlight的“。 – H4mst0R 2014-10-30 21:02:59