Como: Criar um projeto de biblioteca UserControl WPF

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.

ObservaçãoObservação

Caixas de diálogo e comandos de menu que você vê podem diferir das descritas na Help dependendo das suas configurações ativas ou edição. Para alterar as configurações, escolha Import and Export Settings sobre o Ferramentas menu. For more information, see Trabalhando com configurações.

To create a WPF User Control project

  1. Start Visual Studio 2010.

  2. On the File menu, point to New, and then select Project.

    The New Project dialog box appears.

  3. No Modelos instalados painel, expandir Visual Basic ou Visual C# e selecione Windows.

  4. Definir o.NET Frameworkversão-lista suspensa para uma versão que suporta o WPF, como o .NET Framework 4.

  5. Na lista de modelos, selecione Biblioteca de controle de usuário doWPF.

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

  7. No Local caixa de texto, especifique um local para salvar o projeto.

  8. Click OK.

    The WPF Designer for Visual Studio opens, showing UserControl1 of the project you created.

    Observação sobre o Visual BasicObservação sobre o Visual Basic

    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 no Visual Basic.

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

    ObservaçãoObservação

    Para exibir o seu controle de usuário na Toolbox, verifique o Preencher automaticamente os itens da caixa de ferramentas configuração. For more information, see Formatação, XAML, o Editor de texto, caixa de diálogo Opções.

Consulte também

Tarefas

Descreve como usar um controle WPF de terceiros em seu aplicativo WPF.

Como: Criar um novo projeto de aplicativo WPF

Creating a Drawing Application by Using WPF

How to: Create a C# WPF Application

Outros recursos

WPF Designer

Trabalhar com controles no criador de WPF