Changing the ActivityDesignerTheme on an activity

Using an ActivityDesignerTheme is a quick way to customize the appearance of an activity in the workflow designer. But there is a gotcha [:(] Because once you applied the theme and have a workflow with the custom activity open in the designer no matter what you do changes will not be applied.

I am not sure why this is but I suppose the designer caches the color scheme and doesn’t see any changes made to it.

Take the following activity:

using System;
using System.ComponentModel;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Drawing.Drawing2D;

namespace WorkflowConsoleApplication4
{
    [Designer(typeof(MyActivity1ActivityDesigner))]
    public partial class MyActivity: Activity
    {
    }


    [ActivityDesignerTheme(typeof(MyActivity1ActivityDesignerTheme))]
    public class MyActivity1ActivityDesigner: ActivityDesigner
    {
    }

    public class MyActivity1ActivityDesignerTheme : ActivityDesignerTheme
    {
        /// <summary>
        /// Initializes a new instance of the MyActivity1ActivityDesignerTheme class.
        /// </summary>
        public MyActivity1ActivityDesignerTheme(WorkflowTheme theme)
            : base(theme)
        {
            BackColorStart = Color.LightBlue;
            BackColorEnd = Color.Blue;
            BackgroundStyle = LinearGradientMode.ForwardDiagonal;
        }
    }
}

Which look like this in the designer


image


Clearly the background has a blue gradient. Now if I change the theme code to the following:

public class MyActivity1ActivityDesignerTheme : ActivityDesignerTheme
{
    /// <summary>
    /// Initializes a new instance of the MyActivity1ActivityDesignerTheme class.
    /// </summary>
    public MyActivity1ActivityDesignerTheme(WorkflowTheme theme)
        : base(theme)
    {
        BackColorStart = Color.LightCyan;
        BackColorEnd = Color.Cyan;
        BackgroundStyle = LinearGradientMode.ForwardDiagonal;
    }
}

You might expect the activity to change its look to:


image


Unfortunately this doesn’t happen [:(]


Now you can quit Visual Studio and restart it after which the new style will take affect but there is a quicker way. Right click the activity and select “Select Custom Theme…”


image


When the dialog shows just click OK and the designer reads the theme again [:)]


 


image


Enjoy!



www.TheProblemSolver.nl
http://wiki.WindowsWorkflowFoundation.eu

One thought on “Changing the ActivityDesignerTheme on an activity

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>