I've created a custom designer to which I add a new DesignerAction "Insert Required Activities". I've handled the event OnExecuteDesignerAction and in there I add activities to the Activity I'm designing but I can't get them to showup in the designer unless I save and close the workflow then reopen it. I must be missing some method call or event...
I'm just doing this:
baseActivity.Activities.Add(new InputData());
baseActivity.Activities.Add(new OutputData());
I'm assuming I have to raise some event or call a method to cause the designer to redraw the workflow rendering... I've tried Invalidate() PerformLayout()....

Added activities from the DesignerActions and refreshing the designer rendering
Shannon Braun
You should be using this.InsertActivities, sample below:< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
public class Activity1Designer : SequenceDesigner
{
protected override System.Collections.ObjectModel.ReadOnlyCollection<DesignerAction> DesignerActions
{
get
{
List<DesignerAction> designerActions = new List<DesignerAction>();
designerActions.AddRange(base.DesignerActions);
Activity1 act = this.Activity as Activity1;
if (act.Activities["foo"] == null)
designerActions.Add(new DesignerAction(this, 1, "Add new Code activity"));
if (act.Activities["bar"] == null)
designerActions.Add(new DesignerAction(this, 2, "Add new Delay activity"));
return designerActions.AsReadOnly();
}
}
protected override void OnExecuteDesignerAction(DesignerAction designerAction)
{
List<Activity> activitiesToAdd = new List<Activity>();
switch (designerAction.ActionId)
{
case 1:
activitiesToAdd.Add(new CodeActivity("foo"));
break;
case 2:
activitiesToAdd.Add(new DelayActivity("bar"));
break;
default:
base.OnExecuteDesignerAction(designerAction);
break;
}
if (activitiesToAdd.Count > 0)
{
this.InsertActivities(new HitTestInfo(this, HitTestLocations.Designer), activitiesToAdd.AsReadOnly());
}
}
}
The newly added children will always be inserted at index Activities.Count. When you override DesignerActions or OnExcuteDesignerAction make sure you call base. If you want the activities to be add to index 0 then use the following HitTestInfo:
new HitTestInfo(this.ContainedDesigners.Count > 0 this.ContainedDesigners[0] : this, HitTestLocations.Designer)kckc
Above pasted code is giving me error on clicking error tooltip. Error "Object reference not set to an instance of a object".
I pasted the code as it is just by replacing "Activity1" with my cusom activity name.
D_a_v_i_d_B
globim