Add Graphic User Interface to custom Activities

Is possible to create a custom activity and include some GUI, so when that custom activity is used in a workflow the user would be able to double click the custom activity and set properties?
If so, where can I read some documentation about it. I think that, maybe, I need to override some method but I can't figure it out what method.
Thanks in advance.
[364 byte] By [urraca] at [2008-3-3]
# 1

Hi,

It is possible to create a custom activity with your own GUI. For this you need to create your own designer and override the OnPaint method. There are whole bunch of other methods that you can override to associate custom behavior with your designer.

[DesignerAttribute(typeof(MyDesigner))]
[
ToolboxItemAttribute(typeof(ActivityToolboxItem))]
public partial class Activity1 : Sequence
{
public Activity1()
{
InitializeComponent();
}
}

public class MyDesigner : SequenceDesigner
{
public override void OnPaint(......){}

}

Hope this helps.

- Vihang

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
Thanks!! It worked!
But if my custom activity has a property called p1, how can I show the value of that property in my designer?
In the form that appears when i doubleclick the activity I've tried with something like this:

textBox1.Text = ActivitiesLibrary.Activity1.p1Property;

But when I try to compile I get this message:

Error 1 Cannot implicitly convert type 'System.Workflow.ComponentModel.DependencyProperty' to 'string'

I know that is a cast problem, but how should i access the value of property p1 in my form?

namespace ActivitiesLibrary

{

[DesignerAttribute(typeof(MyDesigner))]

[ToolboxItemAttribute(typeof(ActivityToolboxItem))]

public partial class Activity1 : System.Workflow.ComponentModel.Activity

{

public Activity1()

{

InitializeComponent();

}

public static DependencyProperty p1Property = DependencyProperty.Register("p1", typeof(System.String), typeof(ActivitiesLibrary.Activity1));

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

[ValidationVisibilityAttribute(ValidationVisibility.Optional)]

[BrowsableAttribute(true)]

public string p1

{

get

{

return ((string)(base.GetValue(ActivitiesLibrary.Activity1.p1Property)));

}

set

{

base.SetValue(ActivitiesLibrary.Activity1.p1Property, value);

}

}

}

public class MyDesigner : System.Workflow.ComponentModel.Design.ActivityDesigner

{

protected override void OnMouseDoubleClick(System.Windows.Forms.MouseEventArgs e)

{

UI.Form1 f1 = new UI.Form1();

f1.ShowDialog();

}

}

}

namespace UI

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

textBox1.Text = ActivitiesLibrary.Activity1.p1Property;

}

}

}


urraca at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

Sorry, I've realized that I need to receive an instance of my activity in my designer. Something like this:

namespace UI{
public partial class Form1 : Form
{
public Form1(ActivitiesLibrary.Activity1 act)
{
InitializeComponent();
textBox1.Text = act.p1;
}
}
}

What I cant still figure out how is to pass to my designer the instance of the activity doubleclicked:

public class MyDesigner : System.Workflow.ComponentModel.Design.ActivityDesigner
{
protected override void OnMouseDoubleClick(System.Windows.Forms.MouseEventArgs e)
{
UI.Form1 f1 = new UI.Form1();
f1.ShowDialog();
}

Thanks in advance

urraca at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4
Ready. Now its working, I needed to overide Initialize method of my designer.

Sorry..

public class MyDesigner : System.Workflow.ComponentModel.Design.ActivityDesigner

{

private Activity1 m_Act1;

protected override void Initialize(System.Workflow.ComponentModel.Activity activity)

{

m_Act1 = (Activity1) activity;

}

protected override void OnMouseDoubleClick(System.Windows.Forms.MouseEventArgs e)

{

UI.Form1 f1 = new UI.Form1(m_Act1);

// UI.Form1 f1 = new UI.Form1();

f1.ShowDialog();

}

urraca at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5

The deisgner has an Activity Property which gives you the instance of the activity.

protected override void OnMouseDoubleClick(System.Windows.Forms.MouseEventArgs e)
{
UI.Form1 f1 = new UI.Form1(this.Activity);
f1.ShowDialog();
}

Hope this helps.

- Vihang

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 6
Great! I've solved overriding the initialize method, but your sample is much cleaner!.
BTW, is there any way to pass to my designer parameters of the workflow where the custom activity is placed?
Thanks in advance.
urraca at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 7

I am not sure I understand your question. Can you please explain the scenario?

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 8

What I did was to write code in my custom activity to display a form when that custom activity is doubleclicked in the workflow designer, and show in that form values of the custom activity properties.
Now I need to show in that same form, the values of the workflow's parameters.
I hope it will clarify the scenario.
Thanks in advance

urraca at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 9
Can this custom activity designer also be set up to be a drop target for non-activity data? I am trying to use this designer to drop in external parameter data for the activity but the ActivityDesigner only has OnDragEnter and OnDragDrop methods using the ActivityDragEventArgs. It will accept drag operations from toolbox elements but nothing else.
BrianC. at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified