locked
Rehosted WF designer - Dialog property editor parameters RRS feed

  • Question

  • Our application uses re-hosted Visual Studio designer. We had no problem with this, and everything works perfectly. We are also using custom written activities. We implemented various dialog property editors and that is also working. But the problem is that I need to pass some parameter to dialog property editor and I don't know how to do it.

    Precisely, when user is creating new workflow with designer in our application, he can add our custom "User task". That task has property "Resource" which represents user which will perform this task. So I need to call WCF service to get a list of all available users (so I need to pass service reference to dialog property editor) or to directly call service before and pass list of users. Biggest problem is that I have reference to WCF service only in Window which hosts VS workflow designer. If I could get instance to it from activity or dialog property editor, that would be fine. Also I have tried subscribing to WorkflowDesigner.ModelChanged event, but event arguments for that handler are null always and I can't get which activity is added last. Any help/suggestion is appreciated.

    Here is sample user activity:

    public class UserTask : CodeActivity
        {
            private string _resource;
    
            static UserTask()
            {
                AttributeTableBuilder builder = new AttributeTableBuilder();
                            builder.AddCustomAttributes(typeof(UserTask), "Resource", new EditorAttribute(typeof(UserTaskDialogPropertyEditor), typeof(DialogPropertyValueEditor)));
                
                MetadataStore.AddAttributeTable(builder.CreateTable());
            }
    
            public string Resource
            {
                get
                {
                    return _resource;
                }
                set
                {
                    _resource = value;
                }
            }
    
            protected override void Execute(CodeActivityContext context)
            {
    
            }
        }

    And this is property editor:

    public class UserTaskDialogPropertyEditor : DialogPropertyValueEditor
        {
            public UserTaskDialogPropertyEditor()
            {
                this.InlineEditorTemplate = new DataTemplate();
    
                FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
                stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
                Binding labelBinding = new Binding("Value");
                label.SetValue(Label.ContentProperty, labelBinding);
                label.SetValue(Label.MaxWidthProperty, 90.0);
    
                stack.AppendChild(label);
    
                FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));
    
                editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
    
                stack.AppendChild(editModeSwitch);
    
                this.InlineEditorTemplate.VisualTree = stack;
            }
    
            public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
            {
                SelectResourceDialog resourceDialog = new SelectResourceDialog();
                if (resourceDialog.ShowDialog() == true)
                {
    
                }
            }
        }

    Wednesday, July 11, 2012 2:05 PM

Answers

  • Hi,

    If I understood you correctly you  may find your answer Here.

    Thanks,

    Madhur


    MB

    • Marked as answer by brugi82 Thursday, July 12, 2012 9:18 AM
    Thursday, July 12, 2012 3:02 AM
  • Hi,

    If I understood you correctly you  may find your answer Here.

    Thanks,

    Madhur


    MB

    Hello Madhur,

    I have tried that solution and it works. Thank you.

    Also I have been playing a bit, and I have found another solution. It is possible to register service via EditingContext of WorkflowDesigner class. Then get service instance (as you shown in linked post) :

                ModelPropertyEntryToOwnerActivityConverter ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter();
                ModelItem activityItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem;
                EditingContext ec = activityItem.GetEditingContext();
                MyService server = ec.Services.GetService(typeof(MyService )) as MyService ;

    After that, its easy to call service method and get list of available users.

    • Marked as answer by brugi82 Thursday, July 12, 2012 9:18 AM
    Thursday, July 12, 2012 9:18 AM

All replies

  • A little update on situation. I managed to get a list of available users as activity property. So now I have 2 properties Resource (which is selected user) and Avaliable Users. Is there a way to access Avaliable Users from Dialog Property Editor of Resource property? 

    DialogPropertyValueEditor class has ShowDialog method:

    public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)


    Wednesday, July 11, 2012 2:59 PM
  • Hi,

    If I understood you correctly you  may find your answer Here.

    Thanks,

    Madhur


    MB

    • Marked as answer by brugi82 Thursday, July 12, 2012 9:18 AM
    Thursday, July 12, 2012 3:02 AM
  • Hi,

    If I understood you correctly you  may find your answer Here.

    Thanks,

    Madhur


    MB

    Hello Madhur,

    I have tried that solution and it works. Thank you.

    Also I have been playing a bit, and I have found another solution. It is possible to register service via EditingContext of WorkflowDesigner class. Then get service instance (as you shown in linked post) :

                ModelPropertyEntryToOwnerActivityConverter ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter();
                ModelItem activityItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem;
                EditingContext ec = activityItem.GetEditingContext();
                MyService server = ec.Services.GetService(typeof(MyService )) as MyService ;

    After that, its easy to call service method and get list of available users.

    • Marked as answer by brugi82 Thursday, July 12, 2012 9:18 AM
    Thursday, July 12, 2012 9:18 AM