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";
Comments
- Anonymous
April 21, 2015
I set the AttributeTable and added the customAttribute in my class that implements IRegisterMetadata var builder = new AttributeTableBuilder(); builder.AddCustomAttributes(typeof(Activity), "DisplayName", new EditorAttribute(typeof(ReadOnlyStringEditor), typeof(PropertyValueEditor)));
MetadataStore.AddAttributeTable(builder.CreateTable());I can still edit the Designer by clicking on the label and typing text. I also never get hit in the ReadOnlyStringEditor. I don't want the entire designer to be readonly only the displayname. Any ideas?MyDesigner.RegisterMetadata(builder);
- Anonymous
May 19, 2015
@Troy Just want to let you know if you are still looking for a solution. You can set it read-only in workflow designer by setting the read-only property of DisplayName (TextBox) to true in the template from the overridden OnApplyTemplate() in the custom activity as below code snippet shown. public override void OnApplyTemplate() { // Use a decompiler tool to get the TextBox name of DisplayName from System.Activities.Presentation.dll -> // Resource -> System.Activities.Presentation.g.resources -> "system/activities/presentation/workflowelementdesignerdefaulttemplate.baml" TextBox displayName = this.GetTemplateChild("DisplayNameBox_570C5205_7195_4d4e_953A_8E4B57EF7E7F") as TextBox; displayName.IsReadOnly = true; base.OnApplyTemplate(); } Best Regards, Erik Cai Visual Studio WCF and Workflow Tools team