Поделиться через


IActivityToolboxService

During Workflow authoring, customers generally want their Toolbox to be context sensitive. For example, if a specific activity is added to the workflow, then they want to ensure that the Toolbox shows a few additional activities. Or if the activities are removed from the workflow, the toolbox should react appropriately based on the domain requirements.

Of course, in the re-hosted workflow designer world, this is simple as you control the Toolbox control and can ensure that based on the Model changes in the workflow, the host triggers appropriate changes in the Toolbox control.

However, in VS since Toolbox is a VS specific control, we needed something additional. That something additional is the IActivityToolboxService. The API provides the following 4 methods:

 public interface IActivityToolboxService 
    { 
        void AddCategory(string categoryName); 
        void RemoveCategory(string categoryName); 
        void AddItem(string qualifiedTypeName, string categoryName); 
        void RemoveItem(string qualifiedTypeName, string categoryName); 
        IList<string> EnumCategories(); 
        IList<string> EnumItems(string categoryName); 
    }

Hopefully, they are pretty self explanatory.

I have also attached a very basic sample where if the specific activity designer has its OnModelItemChanged event triggered, we use the IActivityToolboxService to edit the Toolbox items in VS. And the OnModelItemChanged would be triggered when the CustomActivity is drag dropped on the workflow.

Please also note that, to remove an item from a specific workflow tab, you should have added it through the IActivityToolboxService there in the first place. Meaning, you would not be able to remove any out of box activities for Workflow1.xaml. The way it works is you add custom activities in the first place and then delete them as needed, depending on the context you are in.

Thanks,

Kushal.

IActivityToolboxService.zip

Comments

  • Anonymous
    September 22, 2010
    Is there a way to have a custom activity hidden from the VS toolbox? I have an activity that is a variant of another activity. The first is for example CustomActivity<T> which is available on the toolbox. In the designer, changing a property of this activity will (when I get it working) morph the activity type definition into CustomActivity<T1....T16>. It is this second activity that I don't want to be visible on the toolbox. Any ideas?