Often have children's shoes in the group ask the same question: How to customize the appearance of the WF4.0 activity. In fact, there are two ways to implement the appearance of custom WF4.0 activities: A way I have implemented in previous posts, see: WF4.0 Combat (11): Mail notification; Another way I'm going to tell you about it. So in this article, I'll go to one of the simplest examples of WF4.0 custom activity appearances in these two different ways.
The first way: Use the [Designer] property. The namespace is: using System.ComponentModel; The code is as follows:
[Designer(typeof(CustomWriteLineDesigner))]
public sealed class CustomWriteLine : CodeActivity
{
[RequiredArgument]
public InArgument<string> Text { get; set; }
protected override void Execute(CodeActivityContext context)
{
Console.WriteLine(context.GetValue(this.Text));
}
}
The Customwritelinedesigner in the code above is a XAML file for customizing skins. The first way code can also be written like this:
[ ("MyActivityDesigner.CustomWriteLineDesigner,MyActivityDesigner")]
public sealed class CustomWriteLine : CodeActivity
{
[RequiredArgument]
public InArgument<string> Text { get; set; }
protected override void Execute(CodeActivityContext context)
{
Console.WriteLine(context.GetValue(this.Text));
}
}
The code for Customwritelinedesigner is as follows:
<sap:activitydesigner x:class= "Myactivitydesigner.customwritelinedesigner"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns:sadc= "Clr-namespace:system.activities.presentation.converters;assembly=system.activities.presentation"
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.Resources>
<sadc:argumenttoexpressionconverter x:key= "Argconverter"/>
</sap:ActivityDesigner.Resources>
<sap:ActivityDesigner.Icon>
<DrawingBrush>
<DrawingBrush.Drawing>
<ImageDrawing>
<ImageDrawing.Rect>
<rect location= "0,0" size= "16,16" ></Rect>
</ImageDrawing.Rect>
<ImageDrawing.ImageSource>
<bitmapimage urisource= "Writeline.jpg" ></BitmapImage>
</ImageDrawing.ImageSource>
</ImageDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</sap:ActivityDesigner.Icon>
<grid >
<Grid.ColumnDefinitions>
<columndefinition width= "Auto"/>
<columndefinition width= "*"/>
</Grid.ColumnDefinitions>
<textblock text= "Text" padding= "0,2,4,2"/>
<sapv:expressiontextbox maxlines= "1" grid.column= "1" width= "200"
expression= "{Binding path=modelitem.message, Mode=twoway, converter= {StaticResource Argconverter}, Converterparameter=in} "
Owneractivity= "{Binding path=modelitem}"/>
</Grid>
</sap:ActivityDesigner>