How can I drag and drop a xaml activity to a WF4 rehosted designer?
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开发者_StackOverflow 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?
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.
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.
精彩评论