none
Custom Activity Designer in VS2010 Editor

    Question

  • Is there a way to make a custom activity have a custom designer inside the VS2010 Workflow Editor?  Every sample that I've ever come across shows how to do this for a hosted designer.  In VS2010, Visual Studio is hosting the designer, so how do I make my custom activity designer work for my custom activity?
    Monday, November 23, 2009 7:40 PM

All replies


  • How are you associating in the re-hosted world?

    There are a couple of ways you can associate the designer with the activity in the VS case.

    1. Designer attribute on your code activity.
    2. If your custom activity is in CustomActivities.dll, you can create your designer in the CustomActivities.Design.dll. Then use the IRegisterMetadata as below to register the activity to the class. Please note that the CustomActivities and the CustomActivities.Design dlls should be in the same folder.
    3. You can override the above two associations in the VS world, with CustomActivities.VisualStudio.Design.dll


    Association Code:

    namespace CustomActivities.Design
    {
        class Metadata : IRegisterMetadata
        {
            public void Register()
            {
                AttributeTableBuilder builder = new AttributeTableBuilder();
                // Register Designers.
                builder.AddCustomAttributes(typeof(Prompt), new DesignerAttribute(typeof(CustomActivities.Design.BasicDesignerWithStyling)));
                // Apply the metadata
                MetadataStore.AddAttributeTable(builder.CreateTable());

            }


        }
    }



    Thanks,
    Kushal.


    Kushal Shah - This posting is provided "AS IS" with no warranties, and confers no rights
    • Proposed as answer by kushals Monday, November 23, 2009 8:37 PM
    Monday, November 23, 2009 8:37 PM
  • Ryan,

    In this tutorial, before the re-hosting stuff is done, it is shown that it works inside VS editor:

    channel9's "Introduction to Workflow 4.0":
    http://channel9.msdn.com/learn/courses/VS2010/WCFWF/IntroToWF/
    video version of that:
    http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Lab-Introduction-to-Workflow-in-NET-4/

    Bottom line: Just ignore the part that talks about re-hosting, and you will get what you want!
    Monday, November 23, 2009 9:32 PM
  • Ryan, I just realized that the tutorial I mention above shows how to associate a custom designer with a CODE activity, but not with a XAML activity.  If it is a XAML activity, you will need to do what Kushal said!

    (Which I am now trying myself, to make sure I understand it.)

    Monday, November 23, 2009 10:04 PM
  • Kushal helped me past a dumb mistake in getting this to work. While awaiting a future blog post by him, here is a summary of what worked for me:

    * Created a solution folder named CustomDesignerForXamlActivity, containing a Workflow Console Application named WorkflowConsoleApplication1, an Activity Library named ActivityLibrary1, and a Designer Library named ActivityLibrary1.Design.

    * Added reference in Console App project to both libraries.

    * In ActivityLibrary / Activity1.xaml, dragged in a WriteLine Activity (or whatever is desired).

    * In ActivityLibrary1.Design / ActivityDesigner1.xaml, replaced the Grid tag block with:

        <StackPanel>
            <Border BorderBrush="Black" BorderThickness="2" CornerRadius="2">
                <TextBlock HorizontalAlignment="Center">TextBlock in Designer</TextBlock>
            </Border>
        </StackPanel>
    

    * Added Metadata.cs to Design library:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Activities.Core.Presentation;
    using System.Activities.Presentation.Metadata;
    using System.ComponentModel;
    using ActivityLibrary1;
    
    namespace ActivityLibrary1.Design
    {
        public class MetaData : IRegisterMetadata
        {
            public void Register()
            {
                DesignerMetadata metaData = new DesignerMetadata();
                metaData.Register();
                AttributeTableBuilder builder = new AttributeTableBuilder();
                // Register Designers.
                builder.AddCustomAttributes(typeof(Activity1), new DesignerAttribute(typeof(ActivityDesigner1)));
                // Apply the metadata.
                MetadataStore.AddAttributeTable(builder.CreateTable());
            }
        }
    }
    


    * Getting that to compile required adding two References (Add Reference...) to the Design project (ActivityLibrary1.Design):
     System.Activities.Core.Presentation module, and project (ActivityLibrary1).

    * The first time I dragged Activity1 into Workflow1.xaml, it just showed the standard collapsed view icon. When I re-built, there was an error "Assembly PresentationFramework ... could not be resolved."   Add Reference / .Net tab / PresentationFramework took care of that.

    * ... But still didn't show my custom view. The problem is that Visual Designer doesn't find my custom ActivityLibrary1.Design.dll, because it is being built in a different bin folder than the related ActivityLibrary1.dll.  I fixed this by changing both Project's build path to be "..\Debug\".  That is, they each now put their dll into a Debug folder within my root solution folder.

    Finally, the custom appearance showed up in Workflow1.xaml.  Specifically, a box with the standard icon, and the name "Activity1", and containing a black rounded rectangle with the text "TextBlock in Designer", which you will see in the Designer XAML I pasted above.

    Now I'll leave it to Kushal to explain this better :)

    Steve

    Tuesday, November 24, 2009 1:17 AM