Share via


Make a control from existing objects

This page applies to WPF projects only

If you have an idea for the design of a control, and you cannot use one of the system controls that come with Microsoft Expression Blend 2, you can create your control on the artboard by drawing the components of your control, and then converting those components to a reusable user control (also named a UserControl).

To make a control from existing objects on the artboard

  1. Click the Selection Cc296387.2ff91340-477e-4efa-a0f7-af20851e4daa(en-us,Expression.10).png tool. Hold the SHIFT key when you select both of your rectangles.

  2. Right-click the selected objects, click Group into, and then select the Canvas panel from the pop-up menu. The rectangles become child objects of a new layout panel.

    Tip

    You can select and right-click objects either on the artboard or under Objects and Timeline (as in the following image).

    Cc296387.7c3b8323-da25-4cfc-9f9d-55808aea711d(en-us,Expression.10).png

    There are many different types of layout panels, each with a different layout scheme. In a Canvas panel, the child objects will not resize with your application window. In a Grid panel, you can configure child objects to autosize and set the alignment and margin properties under Layout in the Properties panel to let the child objects resize with your application window.

  3. Right-click the new canvas object under Objects and Timeline, and then select Make Control from the pop-up menu.

    Cc296387.f2b077d0-a36a-483f-be12-272a66def60e(en-us,Expression.10).png

    The Make Control dialog box appears.

    Cc296387.2a301fcf-3ece-4254-a3d1-654ad98cb9a7(en-us,Expression.10).png

    You can leave the fields as they are and click OK.

    A new user control is created, opened for editing, and visible in the Project tab.

    Cc296387.ff90c77a-6cd2-43c5-b1af-52a1c89c1fee(en-us,Expression.10).png

  4. Build your application (CTRL+SHIFT+B). This will save your files, let the user control be displayed in the main document, and make it available from the Custom Controls tab of the Asset LibraryCc296387.0224cabd-5da1-4e01-bddd-4a647401a098(en-us,Expression.10).png so that you can use it again.

    Cc296387.129e8111-3f37-423d-9439-d3dc3415356c(en-us,Expression.10).png

Next steps

  • You can also make a button from existing objects. This gives you a new button template instead of a new user control. For more information, see Make an object into a button.

  • As an alternative to a user control that inherits from the UserControl class, you can create a custom control that inherits from the Control class or from the system controls that come with Expression Blend 2 (because they also inherit from Control). Such custom controls are compiled into DLL files that you can reference in your project so that you can draw the custom controls on the artboard. Controls that inherit from the Control class can use templates, just like the system controls. For more information, see Try it: Create a custom WPF control and Create or edit a control template.

See also

Concepts

Create a control from existing objects

Make an object into a button

Change the design-time size of a user control