Embedded webbrowser control in winform in WPF

Source: Internet
Author: User
Use vs2008 to create a WPF Application Program To use webbrowser. Adding the webbrowser component from the toolbox to the WPF component finds that many attribute events are unavailable. Decide whether to use webbrowser in winform. To use the winform control in WPF, follow these steps to view msdn.
    1. Create a project namedHostingwfinwpf.

    2. In Solution Explorer, add a reference to the windowsformsintegration Assembly named windowsformsintegration. dll.

    3. In Solution Explorer, add a reference to the Windows form 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. InCodeOpen window1.xaml. CS in the 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 );
}
}
}

Replace maskedtextbox with 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.