wp7 c#LoadCompleted没有触发

时间:2014-10-30 10:17:02

标签: c# events windows-phone-7 oauth

我正在试图找出oauth页面是否已加载。

因此我让我的web浏览器导航到:

"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以进行测试。但我不希望这些信息公开。

为什么会发生这种情况,是否有办法确定页面是否已加载?我现在唯一的想法是在“导航”处理程序中创建一个循环,检查一些与页面相关的值,并在条件匹配时手动触发事件。

但这似乎有点模糊,因为这个页面可以改变,我不想每次更新应用程序,例如改变一些风格......

1 个答案:

答案 0 :(得分:0)

Loaded事件指的是WebBrowser控件。在可视树中加载控件时会触发它。

它与浏览器中的DOMLoaded事件不同。

没有触发的事件等同于DOM Loaded事件 您最近可以监控Navigated事件,然后等待一小段时间才能访问该页面的内容。
请注意,您需要等待,因为Navigated事件将在页面完成之前触发,并且#34;已加载&#34;。那是在浏览器引擎完成布局内容之前,页面上的任何javascript(或链接)已经运行。