Replaced default namespaces in Rehosted Workflow Designer

I am trying to re-create the WF4 Workflow Designer. On the Import tab, I would like to import the default namespace imported. It looks like this:

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

After many studies, I realized that if you look at

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

You will see that already imported. However, adding a namespace to this collection does not seem to have any effect. So my question is: how do I add imported namespaces to this list correctly? Or, how do I get the context for the update using the manually imported namespace import?


Additional information for the solution below :

To solve this problem, I created my desired “clean slide” activity XAML file, added it to my project, set its “Build” action to “Built-in resource” and its “Custom tool” to delete a line.

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 workflow has all the desired imported namespaces.

+3
source share
2 answers

The way I do this does not start with a completely empty workflow, but creates an empty template with the required import. Add something like:

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

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

+2
source

, , , .

, , System.Activities.Presentation.View.ImportDesigner.OnContextChanged(),

ActivityXamlServices.Load(aStream)  // wrong way!

:

OnContextChanged() // of class ImportDesigner

https://referencesource.microsoft.com/#System.Activities.Presentation/System.Activities.Presentation/System/Activities/Presentation/View/ImportDesigner.xaml.cs,1d24713ba95e69c5 .Collection "" . , .

:

ab.Implementation // of the ActivityBuilder ab 

Alex ' .Load() WorkflowDesigner.

:

public static Activity LoadActivityFrom(FileInfo xaml)
{
  using (var rd = xaml.OpenRead())
  using (var xr = new System.Xaml.XamlXmlReader(rd))
  using (var br = System.Activities.XamlIntegration.ActivityXamlServices.CreateBuilderReader(xr))
  {
    var ab = System.Xaml.XamlServices.Load(br) as System.Activities.ActivityBuilder;
    return ab.Implementation;
  }
}
0

All Articles