Workflow Activities

Say I have a user activity that has a dependency property of type GUID.

I want my custom constructor to show as combobox (or its own user control) with possible values ​​to choose from (the values ​​should come from the database).

Is it possible?

+3
source share
1 answer

You need to create UITypeEditor. The following is a template for the combox editor: -

public class MyCustomEditor : UITypeEditor
{
  public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  {
    return UITypeEditorEditStyle.DropDown;
  }
  public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider)
  {
    var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
    var list = new ListBox();

    // Your code here to populate the list box with your items

    EventHandler onclick = (sender, e) => {
      editiorService.CloseDropDown();
    };

    list.Click += onclick;

    myEditorService.DropDownControl(list);

    list.Click -= onclick;

    return (list.SelectedItem != null) ? list.SelectedItem : Guid.Empty;
  }
}

According to your property in the activity: -

[Editor(typeof(MyCustomEditor), typeof(UITypeEditor)]
public Guid MyGuidValue
{
    get { return (Guid)GetValue(MyGuidValueProperty); }
    set { SetValue(MyGuidValueProperty, value); }
}
  • The attribute Editortells PropertyGrid that you created your own editor for this property.
  • GetEditStyle .
  • EditValue.
  • DropDownControl, , .
  • DropDownControl , CloseDropDown.
+3

Source: https://habr.com/ru/post/1723698/


All Articles