備忘録

備忘録

WPFでWindows.FormsのWebBrowserを使う

1) 参照の追加でSystemWindows.FormsとWindowsFormsIntegrationの2つを追加する。

2) MainWindow.xamlを以下のように書き換える

<Window x:Class="WebBrowserTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <wfi:WindowsFormsHost>
            <wf:WebBrowser DocumentCompleted="webBrowser1_DocumentCompleted" x:Name="webBrowser1"/>
        </wfi:WindowsFormsHost>
    </Grid>
</Window>

参考文献
http://stackoverflow.com/questions/12159859/c-sharp-wpf-webbrowser