Designer rehosted and custom activities in the toolbox. RRS feed

  • Question

  • I'm trying to use the designer rehosting example, but add an activity I create in the designer to the toolbox. (http://msdn2.microsoft.com/en-us/library/aa480213.aspx)

    I've managed to add the compiled workflow to the toolbox by specifying the type name and it's location, but the component isn't usable as an activity to a new workflow.

    Via debugger, I suspect that this is because the ToolboxItemAttribute is not present in the code generated.

    So in the Helpers class, in GenerateCodeFromXomlDocument() call I add

    activityTypeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("ToolboxItem", new CodeAttributeArgument(new CodePrimitiveExpression(true))));


    activityTypeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("ToolboxItemAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(true))));

    in the hopes that the attribute will be squirted into the partial class in the MyCode.cs file, but no such luck.

    Does anybody have experience / an idea how to do this?



    Wednesday, October 25, 2006 7:04 AM


  • I was doing it wrong in the wrong location.

    The right location and encantation is in WorkflowDesignerControl.WorkflowLoader:

    internal WorkflowLoader()


    // Create the code compile unit

    codeBesideccu = new CodeCompileUnit();


    CodeNamespace ns = new CodeNamespace("NH");

    ns.Imports.Add(new CodeNamespaceImport("System"));

    ns.Imports.Add(new CodeNamespaceImport("System.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.ComponentModel.Design"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Design"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Serialization"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Compiler"));

    ns.Imports.Add(new CodeNamespaceImport("System.Drawing"));

    ns.Imports.Add(new CodeNamespaceImport("System.Collections"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.Activities"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.Runtime"));


    CodeTypeDeclaration ctd = new CodeTypeDeclaration("Workflow1");


    ctd.IsPartial = true;

    ctd.Attributes = MemberAttributes.Public;

    ////////////////////// add these lines:

    CodeAttributeDeclaration attrdecl = new CodeAttributeDeclaration(


    new CodeAttributeArgument(new CodePrimitiveExpression(true))



    CodeCommentStatement nurisComment = new CodeCommentStatement(new CodeComment("ToolboxItem decoration should do the trick.."));


    ////////////////////// end added lines




    on to the next problem, extracting all the "standard" default namespace and class name ("foo.Workflow1") that it is user selectable, and that no collision occurs with the default when you compile an activity and later want to use it in your toolbox to insert into a new workflow.

    Wednesday, October 25, 2006 7:19 PM