【问题标题】:wp7 c# LoadCompleted not firingwp7 c#LoadCompleted未触发
【发布时间】:2014-10-31 02:06:49
【问题描述】:

我正在尝试确定是否已加载 oauth 页面。

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

"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 用于测试目的。但我不希望这些信息公开。

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    没有触发与 DOM Loaded 事件等效的事件。
    最接近的方法是监视Navigated 事件,然后等待一小段时间再访问页面内容。
    请注意,您需要等待,因为Navigated 事件将在页面完成“加载”之前触发。那是在浏览器引擎完成内容布局以及页面上(或链接自)的任何 javascript 运行之前。

    【讨论】:

    • msdn.microsoft.com/en-us/library/… "设置Source属性或调用Navigate时发生顶级导航。如果发生错误,例如找不到内容,则在错误发生时引发LoadCompleted事件从 Web 服务器返回。...有关处理事件的更多信息,请参阅 Silverlight 的事件概述。"
    猜你喜欢
    • 2013-10-06
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 2016-03-07
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多