How to add a custom icon to WF 4 custom activities (toolbox and designer)
Adding a custom toolbox icon to your custom activity is a simple task yet there are few rules to follow.
To add the custom Icon we use ToolboxBitmap Attribute. like so:
[ToolboxBitmap(typeof(MyActivity),"myIcon.bmp")]
public sealed class MyActivity : NativeActivity
- The icon "myIcon.bmp" must be a bitmap file
- The icon must be 16X16 pixels
- The icon must be compiled as embedded resource in the current assembly
To display a custom icon in the designer you have to write the following xaml in the activity designer definition:
<sap:ActivityDesigner x:Class="MyActivityDesigner.ActivityDesigner1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
<sap:ActivityDesigner.Icon>
<DrawingBrush>
<DrawingBrush.Drawing>
<ImageDrawing>
<ImageDrawing.Rect>
<Rect Location="0,0" Size="16,16" ></Rect>
</ImageDrawing.Rect>
<ImageDrawing.ImageSource>
<BitmapImage
UriSource="..\Resources\activityIcon.ico" >
</BitmapImage>
</ImageDrawing.ImageSource>
</ImageDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</sap:ActivityDesigner.Icon>
enjoy
Manu