Rehosting Workflow 4 Designer将foreach活动添加到工具箱

gba*_*ill 3 .net-4.0 workflow-foundation-4

我正在使用设计器重新托管样本,并试图将泛型类型放入工具箱中,但我似乎无法使其工作.

我尝试过XAML:

<sapt:ToolboxItemWrapper  AssemblyName="{StaticResource AssemblyName}">
    <sapt:ToolboxItemWrapper.ToolName>
        System.Activities.Statements.ForEach
    </sapt:ToolboxItemWrapper.ToolName>
</sapt:ToolboxItemWrapper>
Run Code Online (Sandbox Code Playgroud)

和基于代码:

Type t = Type.GetType("System.Activities.Statements.Foreach, System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
ToolboxItemWrapper w = new ToolboxItemWrapper(t);
category.Add(w);
Run Code Online (Sandbox Code Playgroud)

但是它们似乎都不起作用.有什么建议?

Mau*_*ice 5

你遗漏了什么不起作用,但我认为你不能在设计师的ForEach中添加子活动.

如果是这种情况,因为Body属性是ActivityAction而不是Activity,需要初始化它.有几种方法可以做到这一点,但最简单的方法是在设计器中开始使用ForEachWithBodyFactory,然后将其拖到设计图面上.

以下代码适用于我.我可以将ForEach拖到工作流上并向其添加子项.

var cat = new ToolboxCategory("Standard Activities");
cat.Add(new ToolboxItemWrapper(typeof(ForEachWithBodyFactory<>)));
Run Code Online (Sandbox Code Playgroud)