Share via


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.

Note

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.

Prerequisites

You need the following components to complete this walkthrough:

  • Visual Studio 2010.

Creating the Project

The first step is to create the Windows Forms project.

Note

When hosting WPF content, only C# and Visual Basic projects are supported.

To create the project

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

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

  2. Build the project.

  3. Open Form1 in the Windows Forms Designer.

  4. From the Toolbox, drag an instance of UserControl1 onto the form.

    An instance of UserControl1 is hosted in a new ElementHost control named elementHost1.

  5. With elementHost1 selected, press CTRL+C to copy it to the clipboard.

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

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

See Also

Reference

ElementHost

WindowsFormsHost

Other Resources

Migration and Interoperability

Using WPF Controls

WPF Designer