Recently I had a customer point out the following from the documentation:
Differences in Specifying Toolbox icons
In the Windows Forms Designer framework, you specify a Toolbox icon for your custom control by applying the ToolboxBitmapAttribute to your control class.
In the WPF Designer framework, you use an embedded resource and a naming convention to specify a Toolbox bitmap. In addition, you use the ToolboxBrowsableAttribute to restrict which types in an assembly are available for populating a Toolbox.
Followed by the question "What is the naming convention?"
I thought I'd answer that question by posting to my blog as it is not the first time I've had that question.
First, a note about the ToolboxBrowsableAttribute, it is defined in Microsoft.Windows.Design.dll so you don't want to use it declaratively in your code because that would require making a reference to Microsoft.Windows.Design.dll which will only be available on machines that have Visual Studio 2008 installed. Use the Metadata Store as discussed here and Metadata Assemblies as discussed here.
Toolbox Icon Naming Convention
Type is defined as:
public partial class ProseControl : UserControl
Default namespace: Proseware.Core.Controls
ProseControl.Icon.png is added as an Embedded Resource.
This causes the image at Proseware.Core.Controls.ProseControl.Icon.png from the resources inside the assembly in which ProseControl is contained to be used as the toolbox icon:
(view from reflector)
The naming convention supports multiple image sizes. For the following example:
For the ProseControl type, the following images in the resources will all be found and the best match for size will be used.
Or, alternatively (the ‘.’ After Icon is not required but is acceptable):
If the desired size by the host is 64 pixels by 64 pixels, and Proseware.Core.Controls.ProseControl.Icon.Large.png is the best match based on size and aspect ratio, it will be used. All of the images will be looked at.
If there are 2 images with the same size and aspect ratio, the host will decide which it will use.
Attached to this post is a sample project that illustrates how to get an icon defined for your control. To test, build the solution, right click on the toolbox and click "Choose Items...". Switch to the WPF Components tab and navigate to one of the control assemblies. You will then see your control with it's icon on the toolbox.
Thanks for this -- very useful. This is working for me for displaying toolbox icons in Visual Studio, but I'm not seeing the custom icons in Expression Blend. I've tried your sample project as well, and Blend doesn't pick up the icons from that, so I'm not sure whether this is me being stupid or whether it's a Blend issue. I've tested with both Blend 1 and the Blend 2 December preview. Any suggestions? Thanks!
Blend did not implement this functionality. The only extensibility features that Blend supports is Metadata Loading, Licensing (needs the SDK), and Property Editing.