How to: Create a WPF UserControl Library Project

To combine the functionality of one or more Windows Presentation Foundation (WPF) controls with custom code, you can create a user control, also known as a composite control. User controls combine rapid control development, standard WPF control functionality, and the versatility of custom properties and methods. When you begin creating a user control, you are presented with a visual designer, upon which you can place standard WPF controls. The child controls are known as constituent controls.

These constituent controls retain all their inherent functionality, as well as the appearance and behavior (look and feel) of standard WPF controls. Once these controls are built into the user control, however, they are no longer available to you through code. The user control does its own painting and also handles all the basic functionality associated with controls.

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 Visual Studio Settings.

To create a WPF User Control project

  1. Start a version of Visual Studio that supports WPF development, such as Visual Studio 2008.

  2. On the File menu, point to New, and then select Project. The New Project dialog box appears.

  3. In the Project Types pane, choose the programming language you want to use.

  4. In the Templates pane, choose WPF User Control Library for Visual Basic or Visual C# projects. More information about the selected template is displayed below the Project Types and Templates panes.

    Note

    If you do not see the WPF User Control Library template, make sure that you are targeting a version of the .NET Framework that supports WPF. In the upper-right corner of the New Project dialog box, set the .NET Framework version drop-down list to the .NET Framework 3.0 or later.

  5. In the Name text box, name the project something unique to indicate the control's purpose.

  6. In the Location text box, enter the directory in which you want to save your project, or click the Browse button to navigate to it.

  7. Click OK. The Windows Presentation Foundation (WPF) Designer for Visual Studio opens, showing UserControl1 of the project you created.

    Visual Basic noteVisual Basic Note:

    Every executable file that you create with Visual Basic 2005 contains a namespace with the same name as your project. For more information, see Namespaces in Visual Basic.

  8. Drag controls from the Toolbox onto your user control.

    These controls should be positioned and designed as you want them to appear in the final user control. If you want to allow developers to access the constituent controls, you must declare them as public, or selectively expose properties of the constituent control.

See Also

Tasks

How to: Use a Third-Party WPF Control in a WPF Application

NumericUpDown Custom Control in One Project Sample

How to: Create a New WPF Application Project

Creating a Drawing Application by Using WPF

How to: Create a C# WPF Application

Creating a Drawing Application by Using WPF

Other Resources

WPF Designer

Working with Controls in the WPF Designer