繁体   English   中英

如何使用caliburn.micro WPF抓取webbrowser.document

[英]How to grab webbrowser.document using caliburn.micro WPF

我在WPF中有一个网络浏览器

<WebBrowser x:Name="WebBrowserControl" Width="1000" Height="600" Source="https://www.1.com" cal:Message.Attach="[Event LoadCompleted]=[Action LoadCompleted($eventArgs)]"/>   

它加载了www.1.com,当我单击1.com上的按钮时,它跳转到http://2.com,我听了loadCompleted事件

public void LoadCompleted(NavigationEventArgs e)
{          
    if (e.Uri.AbsoluteUri == "https://www.2.com")
    {
         //Here i want to get WebBrowserControl.Document as mshtml.HTMLDocument;
        MessageBox.Show("Completed loading the page");
    }
}

我想获得2.com htmlDocument。 有没有办法实现这一目标。 我不是以viewmodel的方式实现的。

private void WebBrowserControl_LoadCompleted(object sender, NavigationEventArgs e)
{
    string[] tags = new string[]{};

    if (e.Uri.OriginalString == "https://www.2.com")
    {
        MessageBox.Show("here");
        var document = WebBrowserControl.Document as mshtml.HTMLDocument;                                                           
    }
}   

我做了这样的事情

//view
cal:Message.Attach="[Event LoadCompleted]=[Action LoadCompleted(WebBrowserControl.Document,$eventArgs)]"

//ViewModel
public void LoadCompleted(mshtml.HTMLDocument x ,NavigationEventArgs e)
{
    //it calls this method but the x is null
}
<WebBrowser x:Name="WebBrowserControl" Width="1000" Height="600"  Source="https://www.1.com" cal:Message.Attach="[Event LoadCompleted]=[Action LoadCompleted($source,$eventArgs)]"/>


public void LoadCompleted(object sender ,NavigationEventArgs e)
{
    WebBrowser x = (WebBrowser)sender;
    var document = x.Document as mshtml.HTMLDocument;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM