workflow-foundationworkflow-foundation-4rehostingworkflow-rehosting

Rehosted Workflow Designer default imported namespaces


I'm trying to rehost the WF4 Workflow Designer. In the "Imports" tab, I'd like to have some namespaces imported by default. It looks like this:

Imported namespaces http://imageshack.us/m/850/5383/imports.png

After a lot of research, I figured out that if you look at

workflowDesigner.Context.Items.GetValue<ImportedNamespaceContextItem>().ImportedNamespaces

you'll get to see things that are already imported. However, adding a namespace manually to this collection does not seem to have any effect. My question, therefore, is: How do I add imported namespaces to this list the right way? Or, how do I get the context to refresh using my manually added namespace imports?


Additional information to the solution below:

In order to solve this, I created my desired "clean slate" activity XAML file, added it to my project, set its Build Action to Embedded Resource and its Custom Tool to empty string.

Then, in the code that initializes my WorkflowDesigner, I do the following:

_Wd = new WorkflowDesigner();

_Wd.Load(
    XamlServices.Load(
        ActivityXamlServices.CreateBuilderReader(
            new XamlXmlReader(
                Assembly.GetEntryAssembly().GetManifestResourceStream( "WpfApplication1.New.xaml" )
            )
        )
    ) as ActivityBuilder
);

Now my work flow has all the desirable namespaces imported.


Solution

  • The way I do this is by not starting with a completely empty workflow but creating an empty template with the required imports. Add something like:

     xmlns:si="clr-namespace:System.IO;assembly=mscorlib" 
    

    to the root activity in the XAML file to import System.IO