locked
Accessing Dragged DataObject in IActivityTemplateFactory implementation RRS feed

  • Question

  • Hi all

    I am dragging items from a control in a wpf app and then using IActivityTemplateFactory to add an activity to the workflow designer.

    I set the drag data using WorkflowItemTypeNameFormat on a DataObject and its all a beautiful thing. But...

    I also set data on the DataObject which gives me the original drag source - I need this so that I can set properties on the Activity created by the factory.

    The only way I have figured to do this at the moment is to subscribe to the ModelChanged event on the ModelService, work out the last added Activity and then set the properties from the Data I previously retrieved in a PreviewDrop handler. However, idealy I would like to set these properties when I create the new Activity in the IActivityTemplateFactory.Create(..) method.

    What I am trying to determine is if there is any way to retrieve the dragged DataObject at this point - i.e. from within the IActivityTemplateFactory implementation?

    Thanks in advance

    Chris

    Monday, February 21, 2011 5:38 AM

Answers

  • At the point in time when IActivityTemplateFactory.Create() is being called, the DataObject has already been created and retrieved (it held the IActivityTemplateFactory type info). Drag/drop is probably not completed at this time, but it's difficult if not impossible to get or set the data object, since you are not the receiver of the drag drop events...

    Recap, is the scenario basically that
    1) you can 'preconfigure the activity', without actually creating it, in your configuration view, then
    2) you can drag and drop the preconfigured activity into a workflow?

    So it's like building a template of the activity you want to create?

    Are you using a custom control to initiate the drag/drop event? Or standard workflow toolbox? If you go with a custom control, it seems like you could smuggle data to your workflow template factory in various ways much more convenient than Reflection.Emit.

    • Marked as answer by Andrew_Zhu Monday, February 28, 2011 3:25 AM
    Tuesday, February 22, 2011 7:42 PM

All replies

  • I found what I was looking for by modifying Anders Liu's answer on this post. Works brilliantly using a combination of IActivityTemplateFactory, XamlServices and dynamically generated types.

    Thanks heaps Anders :-)

    • Marked as answer by Chris Wessels Monday, February 21, 2011 10:56 AM
    • Unmarked as answer by Chris Wessels Monday, February 21, 2011 11:31 PM
    Monday, February 21, 2011 10:54 AM
  • ok, actually I still have an issue with this. Using dynamic assemblies is great but in my application I need to add these types as and when required.

    I was hoping that I could add new types to my dynamically generated assembly but alas that is not the case. So using this technique will result in a proliferation of dynamically generated assemblies, one per type. The tree loads on demand and is also dynamic so there is no way to generate all the requried types in one go.

    Has anyone got any ideas on this?

    The scenario is I have an hierarchical tree control which is used to create and represent a configuration. Some of the nodes on this tree can be represented as workflow activities for use in a workflow design. The metadata on the node contains the data necessary to initialise the Activity once it is created on the designer. I do not want the user to have to set these properties, they must be set programmatically.

    I obviously can access this DragSource in the ViewModel behind my View that is rehosting the designer but I need to be able to access this data from my implementation of IActivityTemplateFactory.Create(..).

    Is there an elegant way to do this?

    Monday, February 21, 2011 11:44 PM
  • At the point in time when IActivityTemplateFactory.Create() is being called, the DataObject has already been created and retrieved (it held the IActivityTemplateFactory type info). Drag/drop is probably not completed at this time, but it's difficult if not impossible to get or set the data object, since you are not the receiver of the drag drop events...

    Recap, is the scenario basically that
    1) you can 'preconfigure the activity', without actually creating it, in your configuration view, then
    2) you can drag and drop the preconfigured activity into a workflow?

    So it's like building a template of the activity you want to create?

    Are you using a custom control to initiate the drag/drop event? Or standard workflow toolbox? If you go with a custom control, it seems like you could smuggle data to your workflow template factory in various ways much more convenient than Reflection.Emit.

    • Marked as answer by Andrew_Zhu Monday, February 28, 2011 3:25 AM
    Tuesday, February 22, 2011 7:42 PM