読者です 読者をやめる 読者になる 読者になる

qshinoの日記

Powershell関係と徒然なこと

wpf webbrowser class

wpf webbrowser class

class : System.Windows.Controls.WebBrowser

<Window    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="hdoc" Height="300" Width="300">
  <StackPanel>
    <WebBrowser Name="ax"
      Source="c:¥poi.html" />
  </StackPanel>
</Window>

コード

ソース変更

$ax = $win.FindName("ax")
$ax.Source=uri("c:¥qwe.html")

<!-- Web Browser Control -->
<WebBrowser Name="browser" Source="http://msdn.com" 
  Width="600" Height="600"  />

xaml

<StackPanel>
    <StackPanel Orientation="Horizontal">
        <TextBox Name="address" Width="200" />
        <Button Name="go" Content="Go"/>
    </StackPanel>
    <WebBrowser Name="browser" />
</StackPanel>

C-sharpサンプル

public MainWindow()
{
    InitializeComponent();

    var serviceProvider = (IServiceProvider)webBrowser1.Document;
    if (serviceProvider != null)
    {
        Guid serviceGuid = new Guid("0002DF05-0000-0000-C000-000000000046");
        Guid iid = typeof(SHDocVw.WebBrowser).GUID;
        var webBrowserPtr = (SHDocVw.WebBrowser)serviceProvider
            .QueryService(ref serviceGuid, ref iid);
        if (webBrowserPtr != null)
        {
            webBrowserPtr.NewWindow2 += webBrowser1_NewWindow2;
        }
    }
}

private void webBrowser1_NewWindow2(ref object ppDisp, ref bool Cancel)
{
    // Handle the event.
}

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
internal interface IServiceProvider
{
    [return: MarshalAs(UnmanagedType.IUnknown)]
    object QueryService(ref Guid guidService, ref Guid riid);
}

参考

https://msdn.microsoft.com/ja-jp/library/system.windows.controls.webbrowser(v=vs.110).aspx

http://www.atmarkit.co.jp/fdotnet/dotnettips/814wpfwebbrowser/wpfwebbrowser.html