WebBrowser controls embedded in WinForm in WPF

Source: Internet
Author: User

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.

    1. Create a WPF application project named HOSTINGWFINWPF .

    2. In Solution Explorer, add a reference to the Windowsformsintegration assembly named WindowsFormsIntegration.dll.

    3. In Solution Explorer, add a reference to the Windows forms assembly named System.Windows.Forms.dll.

    4. Open Window1.xaml in the WPF designer.

    5. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.