|
2 | 2 | title: "Creating a WPF Toolbox Control | Microsoft Docs"
|
3 | 3 | ms.date: "11/04/2016"
|
4 | 4 | ms.topic: "conceptual"
|
5 |
| -helpviewer_keywords: |
| 5 | +helpviewer_keywords: |
6 | 6 | - "toolbox control"
|
7 | 7 | - "toolbox"
|
8 | 8 | - "wpf"
|
9 | 9 | ms.assetid: 9cc34db9-b0d1-4951-a02f-7537fbbb51ad
|
10 | 10 | author: "gregvanl"
|
11 | 11 | ms.author: "gregvanl"
|
12 | 12 | manager: jillfra
|
13 |
| -ms.workload: |
| 13 | +ms.workload: |
14 | 14 | - "vssdk"
|
15 | 15 | ---
|
16 | 16 | # Create a WPF Toolbox Control
|
17 |
| -The WPF (Windows Presentation Framework) Toolbox Control template lets you create WPF controls that are automatically added to the **Toolbox** when the extension is installed. This topic shows how to use the template to create a **Toolbox** control that you can distribute to other users. |
18 |
| - |
19 |
| - Starting in Visual Studio 2015, you do not install the Visual Studio SDK from the download center. It is included as an optional feature in Visual Studio setup. You can also install the VS SDK later on. For more information, see [Install the Visual Studio SDK](../extensibility/installing-the-visual-studio-sdk.md). |
20 |
| - |
21 |
| -## Create a WPF Toolbox Control |
22 |
| - |
23 |
| -### Create an extension with a WPF Toolbox Control |
24 |
| - |
25 |
| -1. Create a VSIX project named `MyToolboxControl`. You can find the VSIX project template in the **New Project** dialog under **Visual C#** > **Extensibility**. |
26 |
| - |
27 |
| -2. When the project opens, add a **WPF Toolbox Control** item template named `MyToolboxControl`. In the **Solution Explorer**, right-click the project node and select **Add** > **New Item**. In the **Add New Item** dialog, go to **Visual C#** > **Extensibility** and select **WPF Toolbox Control**. In the **Name** field at the bottom of the window, change the command file name to *MyToolboxControl.cs*. |
28 |
| - |
29 |
| - The solution now contains a user control, a `ProvideToolboxControlAttribute` <xref:Microsoft.VisualStudio.Shell.RegistrationAttribute> that adds the control to the **Toolbox**, and a **Microsoft.VisualStudio.ToolboxControl** Asset entry in the VSIX manifest for deployment. |
30 |
| - |
31 |
| -#### To create the control UI |
32 |
| - |
33 |
| -1. Open *MyToolboxControl.xaml* in the designer. |
34 |
| - |
35 |
| - The designer shows a <xref:System.Windows.Controls.Grid> control that contains a <xref:System.Windows.Controls.Button> control. |
36 |
| - |
37 |
| -2. Arrange the grid layout. When you select the <xref:System.Windows.Controls.Grid> control, blue control bars appear on the top and left edges of the grid. You can add rows and columns to the grid by clicking the bars. |
38 |
| - |
39 |
| -3. Add child controls to the grid. You can position a child control by dragging it from the **Toolbox** to a section of the grid, or by setting its `Grid.Row` and `Grid.Column` attributes in the XAML. The following example adds two labels on the top row of the grid and a button on the second row. |
40 |
| - |
41 |
| - ```xaml |
42 |
| - <Grid> |
43 |
| - <Label Grid.Row="0" Grid.Column="0" Name="label1" /> |
44 |
| - <Label Grid.Row="0" Grid.Column="1" Name="label2" /> |
45 |
| - <Button Name="button1" Click="button1_Click" Grid.Row="1" Grid.ColumnSpan="2" /> |
46 |
| - </Grid> |
47 |
| - ``` |
48 |
| - |
49 |
| -## Renaming the control |
50 |
| - By default, your control will appear in the **Toolbox** as **MyToolboxControl** in a group named **MyToolboxControl.MyToolboxControl**. You can change these names in the *MyToolboxControl.xaml.cs* file. |
51 |
| - |
52 |
| -1. Open *MyToolboxControl.xaml.cs* in the code view. |
53 |
| - |
54 |
| -2. Find the `MyToolboxControl` class and rename it to TestControl. (The fastest way to do this is to rename the class, then select **Rename** from the context menu and complete the steps. (For more information about the **Rename** command, see [Rename refactoring (C#)](../ide/reference/rename.md).) |
55 |
| - |
56 |
| -3. Go to the `ProvideToolboxControl` attribute and change the value of the first parameter to **Test**. This is the name of the group that will contain the control in the **Toolbox**. |
57 |
| - |
58 |
| - The resulting code should look like this: |
59 |
| - |
60 |
| - ```csharp |
61 |
| - [ProvideToolboxControl("Test", true)] |
62 |
| - public partial class TestControl : UserControl |
63 |
| - { |
64 |
| - public TestControl() |
65 |
| - { |
66 |
| - InitializeComponent(); |
67 |
| - } |
68 |
| - } |
69 |
| - ``` |
70 |
| - |
71 |
| -## Build, Test, and Deployment |
72 |
| - When you debug the project, you should find the control installed in the **Toolbox** of the experimental instance of Visual Studio. |
73 |
| - |
74 |
| -### To build and test the control |
75 |
| - |
76 |
| -1. Rebuild the project and start debugging. |
77 |
| - |
78 |
| -2. In the new instance of Visual Studio, create a WPF Application project. Make sure the XAML Designer is open. |
79 |
| - |
80 |
| -3. Find your control in the **Toolbox** and drag it to the design surface. |
81 |
| - |
82 |
| -4. Start debugging the WPF application. |
83 |
| - |
84 |
| -5. Verify that your control appears. |
85 |
| - |
86 |
| -### To deploy the control |
87 |
| - |
88 |
| -1. After you build the tested project, you can find the *.vsix* file in the *\bin\debug\* folder of the project. |
89 |
| - |
90 |
| -2. You can install it on a local computer by double-clicking the *.vsix* file and following the installation procedure. To uninstall the control, go to **Tools** > **Extensions and Updates** and look for the control extension, then click **Uninstall**. |
91 |
| - |
92 |
| -3. Upload the *.vsix* file to a network or to a Web site. |
93 |
| - |
94 |
| - If you upload the file to the [Visual Studio gallery](http://go.microsoft.com/fwlink/?LinkID=123847) Web site, other users can use **Tools** > **Extensions and Updates** in Visual Studio to find the control online and install it. |
| 17 | +The WPF (Windows Presentation Framework) Toolbox Control template lets you create WPF controls that are automatically added to the **Toolbox** when the extension is installed. This topic shows how to use the template to create a **Toolbox** control that you can distribute to other users. |
| 18 | + |
| 19 | +Starting in Visual Studio 2015, you do not install the Visual Studio SDK from the download center. It is included as an optional feature in Visual Studio setup. You can also install the VS SDK later on. For more information, see [Install the Visual Studio SDK](../extensibility/installing-the-visual-studio-sdk.md). |
| 20 | + |
| 21 | +## Create a WPF Toolbox Control |
| 22 | + |
| 23 | +### Create an extension with a WPF Toolbox Control |
| 24 | + |
| 25 | +1. Create a VSIX project named `MyToolboxControl`. You can find the VSIX project template in the **New Project** dialog under **Visual C#** > **Extensibility**. |
| 26 | + |
| 27 | +2. When the project opens, add a **WPF Toolbox Control** item template named `MyToolboxControl`. In the **Solution Explorer**, right-click the project node and select **Add** > **New Item**. In the **Add New Item** dialog, go to **Visual C#** > **Extensibility** and select **WPF Toolbox Control**. In the **Name** field at the bottom of the window, change the command file name to *MyToolboxControl.cs*. |
| 28 | + |
| 29 | + The solution now contains a user control, a `ProvideToolboxControlAttribute` <xref:Microsoft.VisualStudio.Shell.RegistrationAttribute> that adds the control to the **Toolbox**, and a **Microsoft.VisualStudio.ToolboxControl** Asset entry in the VSIX manifest for deployment. |
| 30 | + |
| 31 | +#### To create the control UI |
| 32 | + |
| 33 | +1. Open *MyToolboxControl.xaml* in the designer. |
| 34 | + |
| 35 | + The designer shows a <xref:System.Windows.Controls.Grid> control that contains a <xref:System.Windows.Controls.Button> control. |
| 36 | + |
| 37 | +2. Arrange the grid layout. When you select the <xref:System.Windows.Controls.Grid> control, blue control bars appear on the top and left edges of the grid. You can add rows and columns to the grid by clicking the bars. |
| 38 | + |
| 39 | +3. Add child controls to the grid. You can position a child control by dragging it from the **Toolbox** to a section of the grid, or by setting its `Grid.Row` and `Grid.Column` attributes in the XAML. The following example adds two labels on the top row of the grid and a button on the second row. |
| 40 | + |
| 41 | + ```xaml |
| 42 | + <Grid> |
| 43 | + <Label Grid.Row="0" Grid.Column="0" Name="label1" /> |
| 44 | + <Label Grid.Row="0" Grid.Column="1" Name="label2" /> |
| 45 | + <Button Name="button1" Click="button1_Click" Grid.Row="1" Grid.ColumnSpan="2" /> |
| 46 | + </Grid> |
| 47 | + ``` |
| 48 | + |
| 49 | +## Renaming the control |
| 50 | + By default, your control will appear in the **Toolbox** as **MyToolboxControl** in a group named **MyToolboxControl.MyToolboxControl**. You can change these names in the *MyToolboxControl.xaml.cs* file. |
| 51 | + |
| 52 | +1. Open *MyToolboxControl.xaml.cs* in the code view. |
| 53 | + |
| 54 | +2. Find the `MyToolboxControl` class and rename it to TestControl. (The fastest way to do this is to rename the class, then select **Rename** from the context menu and complete the steps. (For more information about the **Rename** command, see [Rename refactoring (C#)](../ide/reference/rename.md).) |
| 55 | + |
| 56 | +3. Go to the `ProvideToolboxControl` attribute and change the value of the first parameter to **Test**. This is the name of the group that will contain the control in the **Toolbox**. |
| 57 | + |
| 58 | + The resulting code should look like this: |
| 59 | + |
| 60 | + ```csharp |
| 61 | + [ProvideToolboxControl("Test", true)] |
| 62 | + public partial class TestControl : UserControl |
| 63 | + { |
| 64 | + public TestControl() |
| 65 | + { |
| 66 | + InitializeComponent(); |
| 67 | + } |
| 68 | + } |
| 69 | + ``` |
| 70 | + |
| 71 | +## Build, Test, and Deployment |
| 72 | + When you debug the project, you should find the control installed in the **Toolbox** of the experimental instance of Visual Studio. |
| 73 | + |
| 74 | +### To build and test the control |
| 75 | + |
| 76 | +1. Rebuild the project and start debugging. |
| 77 | + |
| 78 | +2. In the new instance of Visual Studio, create a WPF Application project. Make sure the XAML Designer is open. |
| 79 | + |
| 80 | +3. Find your control in the **Toolbox** and drag it to the design surface. |
| 81 | + |
| 82 | +4. Start debugging the WPF application. |
| 83 | + |
| 84 | +5. Verify that your control appears. |
| 85 | + |
| 86 | +### To deploy the control |
| 87 | + |
| 88 | +1. After you build the tested project, you can find the *.vsix* file in the *\bin\debug\* folder of the project. |
| 89 | + |
| 90 | +2. You can install it on a local computer by double-clicking the *.vsix* file and following the installation procedure. To uninstall the control, go to **Tools** > **Extensions and Updates** and look for the control extension, then click **Uninstall**. |
| 91 | + |
| 92 | +3. Upload the *.vsix* file to a network or to a Web site. |
| 93 | + |
| 94 | + If you upload the file to the [Visual Studio gallery](http://go.microsoft.com/fwlink/?LinkID=123847) Web site, other users can use **Tools** > **Extensions and Updates** in Visual Studio to find the control online and install it. |
0 commit comments