现在的位置: 首页 > 综合 > 正文

Rehosting WWF Designerp之从工具箱拖动活动到设计器上

2013年04月21日 ⁄ 综合 ⁄ 共 2066字 ⁄ 字号 评论关闭
    要将活动从工具箱拖放到设计器上去,则在自定义的工具箱中要实现接口IToolboxService。要自己实现这个比较大的接口难度比较大,可心直接从 ToolboxService 类进行继承。这个类提供对 IToolboxService 接口的默认实现。这些在网上都有很多的例子,这里就不多说了。

  接下来就可以用类似下面的代码来将工具箱添加到设计器中的服务里面了。

   MySurface.AddService(typeof(IToolboxService), MyToolBox);

  其中MySurface指的是表面设计器或表面管理器实例,MyToolBox则是自定义工具箱的实例。

  完成这些后设计器就可以利用拖放的功能接受来自工具箱中的控件了。我试过,Form设计器和UserControl设计器都可以接受拖放。但工作流设计器却还是不可以的。为此我查阅过相关的资料在Windows Workflow Foundation - MSDN Forums中找到一篇关于“Designer and the Toolbox”的文章(http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=95682&SiteID=1)。其中有下面的描述:

In drag/drop operations, the workflow designer expects a DataObject[ 13 ] filled with two custom data BLOBS “CF_WINOEDESIGNERCOMPONENTS” and “CF_WINOEDESIGNERCOMPONENTSSTATE”. The code to fill in these values is quite long and Arjun was able to send me those lines though the rest of the sample isn’t ready yet. CF_WINOEDESIGNERCOMPONENTS is a memory stream filled in with the entire activity graph serialized into binary using XomlComponentSerializationService. CF_WINOEDESIGNERCOMPONENTSSTATE is also a memory stream, which contains the state for each designer of each activity in the graph.

并且在其后还有下面的内容:

Hopefully we will see the Microsoft sample soon, but I sincerely hope many of these steps are simplified into a helper component that can be released soon and included in the next beta cycle.

看到希望是渺茫了!

后来又找到下面文章“Windows Workflow Foundation: Everything About Re-Hosting the Workflow Designer”(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/WFDsgnRehst.asp),在这里面工具箱对CF_WINOEDESIGNERCOMPONENTS进行了实现(分别在序列化方法和反序列化方法中)。虽然如此,这两个方法并没有在运行时进行调用,然而这个例子却真的能够实现活动的拖放,这让我感到迷惑。

那么究竟是什么影响着拖放的关键所在?我仔细的研究了一下这个例子的MouseDown事件,除了一行语句外没有什么特别的事情,

ToolboxItem toolboxItem = ToolboxService.GetToolboxItem(selectedItem.ComponentClass);对正是ToolboxService.GetToolboxItem方法起了关键作用。在调用IToolboxServiceSerializeToolboxItem方法时所传递的参数必须从ToolboxService.GetToolboxItem进行返回,而不能通过下面的方式将CurToolItem作为参数。

Type typ = typeof(CodeActivity);

_CurToolItem = new ToolboxItem(typ);

否则拖放操作就会泡汤。

  有关Rehosting WWF Designer的文章请参阅我的另外几篇文章:
  WWF的一些技术细节与应用体会(一)
  WWF的一些技术细节与应用体会(二)
  Rehosting WWF 设计器 之运行时定制活动的外观
  Rehosting WWF Designer 之定制活动的外观
  
Rehosting WWF Designerp之从工具箱拖动活动到设计器上
  Rehosting WWF 设计器

抱歉!评论已关闭.