views:

427

answers:

1

I am using the designer rehosting samples and am trying to put the generic types into the toolbox, however I can't seem to make it work.

I've tried XAML based:

<sapt:ToolboxItemWrapper  AssemblyName="{StaticResource AssemblyName}">
    <sapt:ToolboxItemWrapper.ToolName>
        System.Activities.Statements.ForEach
    </sapt:ToolboxItemWrapper.ToolName>
</sapt:ToolboxItemWrapper>

and code based:

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);

however neither of them seem to work. Any suggestions?

+1  A: 

You are leaving out what isn't working but I assume you can't add a child activity to the ForEach in the designer.

If that is the case that is because the Body property is an ActivityAction not an Activity and it needs to be initialized. There are several ways of doing this but the easiest is to get started with the ForEachWithBodyFactory in the designer and drag that onto the design surface instead.

The following code works for me. I can drag the ForEach onto a workflow and add child items to it.

var cat = new ToolboxCategory("Standard Activities");
cat.Add(new ToolboxItemWrapper(typeof(ForEachWithBodyFactory<>)));
Maurice
When I get the type of the generic activity, it gives me a null type (because it is generic and I am not specifying the generic type) The same applies if I use the ForEachWithBodyFactory.
gbanfill
See the code sample I added to the response.
Maurice