Changing activities Id's
Hi.
I have an application that embedds the workflow. In some point of the application, I let the user change the activity Id through a custom form of mine, but that seems to generate a problem. When the user changes the Id, and then drags another activity of the same type to the workflow, it throws an exception saying that the activity already exists.
The code that I write to change the activity ID is quite simple:
activity.ID = "someNewID";
//Perhaps I have to do something else after this code...
I'm with the Beta 1.
Any clues?
Thanks in advance.
[570 byte] By [
Matt] at [2007-12-18]
Hi Vihang.
Sorry about the delay on answering, I've been away 4 a while.
Yes, I am implementing the service, it is the one that came on the example http://www.windowsworkflow.net/Downloads/Examples/Workflow%20Designer%20Control%20-%202005-09-24.exe
On the WorkflowDesignerControl project (it can be downloaded on the link above), I'm creating a new Custom Activity, and then adding it into the Toolbar (via the "ToolboxItems.txt" file)
Here's the code of the Activity:
| |
[DesignerAttribute(typeof(CustomDesigner))] [ToolboxItemAttribute(typeof(ActivityToolboxItem))] public partial class Activity1 : System.Workflow.ComponentModel.Activity { public Activity1() { InitializeComponent(); } }
public class CustomDesigner : ActivityDesigner { protected override void OnMouseDoubleClick System.Windows.Forms.MouseEventArgs e) { Form f = new Form(); TextBox t = new TextBox(); Button b = new Button(); f.Text = "Change the Activity Id"; f.Size = new Size(200, 100); t.Size = new Size(120, 30); b.Size = new Size(50, t.Size.Height); b.Text = "Ok"; f.Controls.Add(t); f.Controls.Add(b); t.Location = new Point(15, 20); b.Location = new Point(140, 20); b.Click += new EventHandler(b_Click); f.ShowDialog(); this.Activity.ID = t.Text; } void b_Click(object sender, EventArgs e) { ((Form)((Button)sender).Parent).Close(); } }
|
As you can see, I'm implementing a CustomDesigner that shows me a form to edit the Activity's Id.
When I do this, the Activity Id changes, but the Text of the activity remains unchanged. And if I drag another "Activity1" to the workflow, nothing happens, I have to drag it again and it appears, but the xoml is broken at this point. It has 3 activities when it should have 2.
If I edit the property from the property grid it works fine.
I'm working on Beta 1.2.
Any help would be appreciated, and thanks in advance.
Matt_
Designer will not behave properly if you assign directly to ID property.
You need to replace last line in OnMouseDoubleClick method with following:
TypeDescriptor.GetProperties(this.Activity)["ID"].SetValue(Activity, t.Text);
this.Text = t.Text;
You have to put the class name and the assembly where the class is, like this:
MyCompany.Activities.MyCustomActivity, MyCompany.Activities
I did that and everything was fine.
What I'm really trying to do is add activities to the toolbox at runtime. I noticed that the IToolboxService interface seems to suggest that its possible (via the AddToolboxItem method). I tried to implement the AddToolboxItem method, adding in code to insert the ToolboxItem into the Listbox. The problem I'm having is that it seems once the control is loaded it ignores any additions to the toolbox's listbox. Is this a design limitation?