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

时间:2016-04-14 01:54:33

标签: c# wpf xaml data-binding caliburn.micro

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

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

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

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

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

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

我做了类似的事

CREATE TABLE `players` (
`PlayerID` int(10) UNSIGNED NOT NULL,
`PlayerName` varchar(255) NOT NULL,
`CountryID` varchar(255) NOT NULL,
`FirstPositionID` int(11) UNSIGNED NOT NULL,
`SecondPositionID` int(10) UNSIGNED NOT NULL,
`Overall` int(11) UNSIGNED NOT NULL,
`Defence` int(11) NOT NULL,
`Speed` int(11) NOT NULL,
`Rebound` int(11) NOT NULL,
`Stamina` int(11) NOT NULL,
`TeamID` int(11) NOT NULL,
`Shooting` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf16;

CREATE TABLE `positions` (
`PositionID` int(10) UNSIGNED NOT NULL,
`PositionName` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf16;





//-----------php-----------------------

    $sql= "SELECT * from players,positions";
    $reg = mysqli_query($con,$sql);
    if(mysqli_num_rows($reg) > 0)
    {
        while($row = mysqli_fetch_assoc($reg))
        {
            echo "</br>Player:".$row['PlayerName']." Overall:".$row['Overall']." Position: ".$row['PositionName'];
        }

    }
    else 
    {
        echo "SQL error at: </br> ".$register."SYNTAX:</br>".mysqli_error($con)."</br>";
    }

1 个答案:

答案 0 :(得分: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;
}