简体   繁体   中英

How to grab webbrowser.document using caliburn.micro WPF

I have a web browser in WPF

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

It loads the www.1.com and when i click a button on 1.com it jump to http://2.com I listen to loadCompleted event

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");
    }
}

I want to get 2.com htmlDocument. is there a way to achieve that. I achieve that in not viewmodel way.

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;                                                           
    }
}   

I did something like this

//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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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