Walkthrough: Copying and Pasting an ElementHost Control into Separate Windows Forms
This walkthrough shows you how to copy a Windows Presentation Foundation (WPF) control from one Windows Form to another.
In this walkthrough, you perform the following tasks:
Create the project.
Copy a WPF Control.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Customizing Development Settings in Visual Studio.
You need the following components to complete this walkthrough:
- Visual Studio 2012.
Creating the Project
The first step is to create the Windows Forms project.
When hosting WPF content, only C# and Visual Basic projects are supported.
To create the project
- Create a new Windows Forms Application project in Visual Basic or Visual C# named
Copying a WPF Control
After you add a WPF control to the project, you can copy it to other forms in the project.
To copy a WPF control
Add a new WPF UserControl project to the solution. Use the default name for the control type,
UserControl1.xaml. For more information, see Walkthrough: Creating New WPF Content on Windows Forms at Design Time.
Build the project.
Form1in the Windows Forms Designer.
From the Toolbox, drag an instance of
UserControl1onto the form.
An instance of
UserControl1is hosted in a new ElementHost control named
elementHost1selected, press CTRL+C to copy it to the clipboard.
Add a new Windows Form to the project. Use the default name for the form type,
Form2open in the Windows Forms Designer, press CTRL+V to paste a copy of
elementHost1onto the form.
The copied control is also named
elementHost1, because it is a private field of the
Form2class. There is no name collision with the