1

I understand that the WorkflowDesigner can receive a dragged item in several ways, for example:

  • By dragging an item from the toolbox and dropping it on the designer: an empty activity of that type will be inserted on the designer at the drop location.
  • One can also drag an activity from the designer and drop it on another location in the designer, the dragged activity will be inserted at the drop location as well.

Is it possible that similar to these two drag and drop mechanism, I can drag a xaml activity to the designer? What I have in mind is this,

Let's say you have a ListView containing several xaml files. I want to be able to drag one of the ListView items (ie one of the xaml files), and when I drag it over the designer it will act as if I drag something from the toolbox (except the activity will be supplied from the xaml). I know I can create a runtime Activity from the file by using ActivityXamlServices.Load(filename), and I want this activity to be inserted at the drop location. But how to tell the application to understand this when I drag and drop?

2 Answers 2

1

Given WorkflowDesigner designer, Activity activity, and drag source dataSource, use this code (credits to tilovell)

ModelItem mi = designer.Context.Services.GetService<ModelTreeManager>()
    .CreateModelItem(null, activity);
DataObject data = new DataObject(DragDropHelper.ModelItemDataFormat, mi);
DragDrop.DoDragDrop(dataSource, data, DragDropEffects.Copy);

The application will go into drag and drop mode. The designer will receive the drop as an Activity.

5
  • So what is activity here? A compiled activity type, something loaded with ActivityXamlServices or something else altogether. And if it isn't a compiled activity what is the generated xaml like when you save the workflow?
    – Maurice
    Jan 3, 2011 at 7:58
  • something loaded with ActivityXamlServices.
    – Louis Rhys
    Jan 3, 2011 at 9:07
  • Activity activity = ActivityXamlServices.Load(filename);
    – Louis Rhys
    Jan 3, 2011 at 9:09
  • Interesting, normally XAML elements refer to .NET types but ActivityXamlServices.Load() doesn't return a type or an instance of something that exists as a type. Is the complete activity tree loaded with ActivityXamlServices.Load() inserted into the final XAML?
    – Maurice
    Jan 3, 2011 at 13:09
  • yes. The behaviour is exactly the same as if I dragged a dynamic activity to that spot
    – Louis Rhys
    Jan 7, 2011 at 9:01
0

You can't do this because activities added to a workflow need to be compiled. When you create a XAML activity and compile your project in VS2010 the resulting compiled activity type is added to the toolbox, not a reference to the XAML file you created.

4
  • are you sure? runtime (non-compiled) activities can be added for example when pasting or drag and dropping another activity to the designer.
    – Louis Rhys
    Dec 30, 2010 at 15:46
  • looking at this blogpost is it possible to do that using DragDrop.DoDragDrop? what would be the DataObject?
    – Louis Rhys
    Dec 30, 2010 at 16:20
  • I am referring to Nick's comment in the comment section
    – Louis Rhys
    Dec 30, 2010 at 16:22
  • It should be a fully qualified type name so Type.GetType() return the type. Meaning the activity should be a .NET type and therefore compiled.
    – Maurice
    Dec 31, 2010 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.