WF4 Rehosted Designer OnActivityAdded Event?

I am looking to re-create a workflow designer. I want to be able to run some code whenever a user adds activity to a design poll. Does an event occur when a user adds activity during development? Or is there some kind of event that I can use? Thanks!

+4
source share
1 answer

For those who might stumble upon this, this is what I understood ...

First, when creating a workflow designer, you need to subscribe to the ModelChanged event.

_workflowDesigner = new WorkflowDesigner(); _workflowDesigner.Load(new Sequence()); ModelService ms = _workflowDesigner.Context.Services.GetService<ModelService>(); if (ms != null) ms.ModelChanged += new EventHandler<ModelChangedEventArgs>(ms_ModelChanged); 

My event handler looks like this:

  void ms_ModelChanged(object sender, ModelChangedEventArgs e) { if (e.ItemsAdded != null && e.ItemsAdded.Count<ModelItem>() == 1) { ModelItem item = e.ItemsAdded.FirstOrDefault<ModelItem>(); var test = item.GetCurrentValue() as MyActivityType; if (test != null && test.Id == null) { //do whatever initialization logic is needed here } } } 

I need to give this source to point me in the right direction.

One thing to take care of is that when you move an activity inside the model, two things happen: delete and add. Right now I don’t have to worry about whether I am adding or moving activity, how can I determine if it was initialized, but if you need to know if something is really added to the model, you may need to track both events .

+3
source

All Articles