Original: WebBrowser controls embedded in WinForm in WPF
Using VS2008 to create a WPF application requires the use of WebBrowser. Adding webbrowser in the WPF component from the Toolbox found that many of these property events are not available. Decide whether to use WebBrowser in WinForm. To use the WinForm control in WPF, review MSDN with the following steps.
Create a WPF application project named HOSTINGWFINWPF .
In Solution Explorer, add a reference to the Windowsformsintegration assembly named WindowsFormsIntegration.dll.
In Solution Explorer, add a reference to the Windows forms assembly named System.Windows.Forms.dll.
Open Window1.xaml in the WPF designer.
Replace the automatically generated XAML in Window1.xaml with the following XAML.
<window x:class= "Hostingwfinwpf.window1"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Title= "HOSTINGWFINWPF"
Loaded= "WindowLoaded"
>
<grid name= "Grid1" >
</Grid>
</Window>
6. Open Window1.xaml.cs in the Code Editor.
7. Replace the code in Window1.xaml.cs with the following code.
Using System;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Data;
Using System.Windows.Documents;
Using System.Windows.Media;
Using System.Windows.Shapes;
Using System.Windows.Forms;
Namespace HOSTINGWFINWPF
{
public partial class Window1:window
{
Public Window1 ()
{
InitializeComponent ();
}
private void WindowLoaded (object sender, RoutedEventArgs e)
{
Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
New System.Windows.Forms.Integration.WindowsFormsHost ();
Create the MaskedTextBox control.
MaskedTextBox mtbdate = new MaskedTextBox ("00/00/0000");
Assign the MaskedTextBox control as the host control ' s child.
Host. Child = Mtbdate;
ADD the interop host control to the Grid
Control ' s collection of child controls.
THIS.GRID1.CHILDREN.ADD (host);
}
}
}
Here, replace the MaskedTextBox with the System.Windows.Forms.WebBrowser.