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 Working with Settings.
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 CopyElementHost. For more information, see How to: Create a New Windows Forms Application Project.
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.
Open Form1 in the Windows Forms Designer.
From the Toolbox, drag an instance of UserControl1 onto the form.
An instance of UserControl1 is hosted in a new ElementHost control named elementHost1.
With elementHost1 selected, 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, Form2. For more information, see How to: Add Windows Forms to a Project.
With Form2 open in the Windows Forms Designer, press CTRL+V to paste a copy of elementHost1 onto the form.
The copied control is also named elementHost1, because it is a private field of the Form2 class. There is no name collision with the elementHost1 in the Form1 class.