2016-04-14 43 views
0

我在WPF Web浏览器如何使用WPF caliburn.micro

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

它加载抢webbrowser.document的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的。有没有办法做到这一点。我以非视角模式实现这一点。

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 
} 

回答

0
<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; 
} 
相关问题