无法将事件处理程序附加到我的控件?

发布于 2024-12-15 01:37:48 字数 580 浏览 2 评论 0原文

我正在(缓慢地)完成我的第一个 Windows Phone 7 应用程序,我想做的是将 LoadCompleted 事件附加到 Web 浏览器控件(这样我就可以在页面上调用一些 javascript 以自动登录我的服务台)。

问题是我不知道如何将事件附加到我的控件。 MSDN 给出了处理程序的代码,但我一无所知: public event LoadCompletedEventHandler LoadCompleted

有人可以帮我修复下面的函数,使其与 loadcompleted 事件一起使用吗?

    private void PageLoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) 
    {
        if (e.Uri.ToString() == MainPage.HelpDeskUrl)
        {
            MessageBox.Show("Page is loaded!");
            // invoke login code will go here
        }
    }

I'm working my way (slowly) through my first windows phone 7 app, and what I'm trying to do is attach the LoadCompleted event to a web browser control (so I can then invoke some javascript on the page to auto login to my helpdesk).

The problem is I can't figure out how to attach the event to my control. MSDN gives this code for the handler but I'm clueless:
public event LoadCompletedEventHandler LoadCompleted

Can someone help me out with the fix to my function below to make it work with the loadcompleted event?

    private void PageLoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) 
    {
        if (e.Uri.ToString() == MainPage.HelpDeskUrl)
        {
            MessageBox.Show("Page is loaded!");
            // invoke login code will go here
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-12-22 01:37:48

将加载完成事件处理程序附加到 Windows 应用程序页面可以通过两种方式完成:

首先,在 page.xaml 中声明加载事件处理函数,如下所示

 <phone:PhoneApplicationPage 
    x:Class="Hubtile.AnimationPage" Loaded="PhoneApplicationPage_Loaded"
    shell:SystemTray.IsVisible="True">

中添加加载事件的事件处理程序,如下所示:

Loaded += new RoutedEventHandler(Page_Loaded);

;其次,在 page.xaml.cs 构造函数 Page_Loaded 如下所示

void Page_Loaded(object sender, RoutedEventArgs e)
   {
     // add code  
     MessageBox.Show("Page is loaded!");
   }

Attaching load completed event handler to Windows application page can be done in two ways

Firstly by declaring loaded event handler function in page.xaml as below

 <phone:PhoneApplicationPage 
    x:Class="Hubtile.AnimationPage" Loaded="PhoneApplicationPage_Loaded"
    shell:SystemTray.IsVisible="True">

Secondly by adding event handler for loaded event in page.xaml.cs constructor as specified below

Loaded += new RoutedEventHandler(Page_Loaded);

function Page_Loaded looks like as below

void Page_Loaded(object sender, RoutedEventArgs e)
   {
     // add code  
     MessageBox.Show("Page is loaded!");
   }
无力看清 2024-12-22 01:37:48

您可以在 xaml 中添加 Web 浏览器控件的加载完成事件,如下所示

处理函数如下
私有无效 myWebBrowser_LoadCompleted(对象发送者,NavigationEventArgs e)
{
MessageBox.Show("完成");
或者

在调用导航函数之前向 Web 浏览器控件添加事件处理程序。
myWebBrowser.LoadCompleted +=new LoadCompletedEventHandler(myWebBrowser_LoadCompleted);

you can add the load completed event for web browser control in xaml as follows

handling function is as follows
private void myWebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
MessageBox.Show("Done");
}

or by adding event handler to the web browser control before calling navigate function.
myWebBrowser.LoadCompleted +=new LoadCompletedEventHandler(myWebBrowser_LoadCompleted);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文