Making an activity's display name readonly in the Workflow 4 designer

To make an activity's display name readonly, it isn't enough to use the ReadOnlyAttribute on the DisplayName. In order to do this, create a custom PropertyValueEditor that displays a string in a text block, then declare an editor attribute on the "DisplayName" property of your activity. The following code demonstrates how to create a read-only custom PropertyValueEditor.

 public class ReadOnlyStringEditor : PropertyValueEditor

{

    public ReadOnlyStringEditor()

    {

        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));

        factory.SetBinding(TextBlock.TextProperty, new Binding("Value"));

        this.InlineEditorTemplate = new DataTemplate();

        this.InlineEditorTemplate.VisualTree = factory;

    }

}

 

The following code demonstrates how to assign the custom property editor. This should be done in the constructor for the designer.\

 // Add attribute onto MyCustomActivity.DisplayName

AttributeTableBuilder builder = new AttributeTableBuilder();

builder.AddCustomAttributes(typeof(Activity), "DisplayName", new EditorAttribute(typeof(ReadOnlyStringEditor), typeof(PropertyValueEditor)));

MetadataStore.AddAttributeTable(builder.CreateTable());

Finally, assign the display name in the custom activity's constructor.



 this.DisplayName = "Custom Sequence Activity";