ToolboxService class and Workflow Designer Rehosting sample
Hello,
Are there any plans to update Workflow Designer Rehosting sample with System.Drawing.Design.ToolboxService class used for part of Toolbox implementation?
Or maybe anyone could share an example how System.Drawing.Design.ToolboxService class could be re-used with Worklfow Designer control?
I have not managed to set it up correctly so far.
Thanks in advance
Edmundas
[413 byte] By [
Edmundas] at [2007-12-24]
Hello,
Thanks for the link, but the sample provided above does not use System.Drawing.Design.ToolboxService class. There is a custom ToolboxService class implemented in the sample, it derives from the System.Windows.Forms.Panel and implements IToolboxService interface.
I would like to re-use System.Drawing.Design.ToolboxService for similar purpose, because it already contains base IToolboxService implementation.
But for now I cannot make it work with Workflow Designer control, so I am curious if anyone tried to achieve this and succeeded?
Edmundas
Hello,
My problem is that workflow designer control does not accept toolbox items dragged from the toolbox on top of the design surface.
I have a listbox as a toolbox that contains items of type System.Drawing.Design.ToolboxItemContainer (I override Paint method to paint listbox items as toolbox items). I use Listbox.MouseMove event handler to initiate toolbox item drag operation (similar to the method implemented in Workflow Designer Rehosting sample).
I guess the problem is caused by the IDataObject object that I am passing as drag drop data object. I am not sure what data should I package there. Currently I tried following ways, none of them worked though (see commented lines):
private void OnListBoxMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && this._listBox.SelectedItem != null)
{
ToolboxItemContainer toolboxItemContainer = _listBox.SelectedItem as ToolboxItemContainer;
if (toolboxItemContainer != null)
{
ToolboxItem toolboxItem = toolboxItemContainer.GetToolboxItem(null);
DataObject dataObject = new DataObject();
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(memoryStream, toolboxItemContainer);
memoryStream.Position = 0;
BinaryReader a = new BinaryReader(memoryStream);
byte[] buffer = a.ReadBytes((int)memoryStream.Length); //dataObject.SetData("CF_TOOLBOXITEMCONTAINER", toolboxItemContainer);
//dataObject.SetData("CF_TOOLBOXITEMCONTAINER", buffer);
//dataObject.SetData("CF_TOOLBOXITEMCONTAINER_CONTENTS", toolboxItem);
//dataObject.SetData(typeof(ToolboxItem), toolboxItem);
DragDropEffects effects = DoDragDrop(dataObject as IDataObject, DragDropEffects.Copy | DragDropEffects.Move);
}
}
}
Edmundas
You don't need to do the actually packaging (nor do you want to because of Activities with a ToolboxItem) here is code I've used (where _wview is the WorkflowView - although any serviceprovider should be able to find those services):
IDataObject ret =
null;if (toolboxItem != null){
IComponent[] components = toolboxItem.CreateComponents();
Activity[] activities =
null;if(components!=null)activities =
new Activity[components.Length];if (activities != null){
components.CopyTo(activities, 0);
ComponentSerializationService service = ((
IServiceProvider)_wview).GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;if (service != null)ret = CompositeActivityDesigner.SerializeActivitiesToDataObject(
this._wview, activities);}
}
return ret;I am also having difficulties with the ToolboxService implementation from the designer rehosting example.
After dragging activities into the form, my main menu becomes very slooooooow and the toolbox and workflow designer are not refreshed correctly (screen fragments are not updated, when the size of the Toolbox is changed).
Would it be possible for you to provide your Toolbox implementation to the public as an example?