WF4.0 Combat (23): Two ways to customize the appearance of a workflow activity

Source: Internet
Author: User
Tags xmlns

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.