先创建一个WinForm应用程序吧,再放SplitContainer,再工具箱WPF项下elementHost分别放三个,如下

再添加一个类,factory.cs
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Presentation;
using System.Activities.Presentation.Hosting;
using System.Windows;
using System.Windows.Controls;
using System.Activities.Presentation.Toolbox;
using System.Activities.Statements;
namespace WindowsFormsApp3
{
public class factory
{
private WorkflowDesigner wd;
private string DefaultXamlActivity
{
get
{
return @"<Activity x:Class='EmptyActivity' mva:VisualBasic.Settings='Assembly references and imported namespaces serialized as XML namespaces' xmlns='http://schemas.microsoft.com/netfx/2009/xaml/activities' xmlns:mva='clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' />";
}
}
public void RegisterMetadata()
{
System.Activities.Core.Presentation.DesignerMetadata designers = new System.Activities.Core.Presentation.DesignerMetadata();
designers.Register();
}
public UIElement LoadDesigner(string xaml)
{
this.wd = new WorkflowDesigner();
this.wd.Context.Items.GetValue<ReadOnlyState>().IsReadOnly = false;
this.wd.ModelChanged += delegate (object source, EventArgs args)
{
this.wd.Flush();
};
this.wd.Text = string.IsNullOrEmpty(xaml) ? this.DefaultXamlActivity : xaml;
this.wd.Load();
Grid.SetColumn(this.wd.View, 1);
UIElement element = this.wd.View;
element.IsEnabled = true;
element.IsHitTestVisible = true;
return element;
}
public UIElement LoadPropertyInspector()
{
Grid.SetColumn(wd.PropertyInspectorView, 2);
return wd.PropertyInspectorView;
}
public UIElement LoadToolBox()
{
ToolboxControl tc = GetToolboxControl();
Grid.SetColumn(tc, 0);
return tc;
}
private ToolboxControl GetToolboxControl()
{
ToolboxControl ctrl = new ToolboxControl();
#region MS Built-in Activity
ToolboxCategory categoryFlowchart = new ToolboxCategory("Flowchart")
{
new ToolboxItemWrapper(typeof(Flowchart)),
new ToolboxItemWrapper(typeof(FlowDecision))
};
ToolboxCategory categoryCollection = new ToolboxCategory("Collection")
{
new ToolboxItemWrapper(typeof(AddToCollection<>)),
new ToolboxItemWrapper(typeof(ClearCollection<>)),
new ToolboxItemWrapper(typeof(ExistsInCollection<>)),
new ToolboxItemWrapper(typeof(RemoveFromCollection<>)),
};
ToolboxCategory categoryPrimitives = new ToolboxCategory("Primitives")
{
new ToolboxItemWrapper(typeof(Assign)),
new ToolboxItemWrapper(typeof(Assign<>)),
new ToolboxItemWrapper(typeof(Delay)),
new ToolboxItemWrapper(typeof(InvokeMethod)),
new ToolboxItemWrapper(typeof(WriteLine)),
};
ToolboxCategory categoryControlFlow = new ToolboxCategory("ControlFlow")
{
new ToolboxItemWrapper(typeof(DoWhile)),
new ToolboxItemWrapper(typeof(ForEach<>)),
new ToolboxItemWrapper(typeof(If)),
new ToolboxItemWrapper(typeof(Parallel)),
new ToolboxItemWrapper(typeof(ParallelForEach<>)),
new ToolboxItemWrapper(typeof(Pick)),
new ToolboxItemWrapper(typeof(PickBranch)),
new ToolboxItemWrapper(typeof(Sequence)),
new ToolboxItemWrapper(typeof(Switch<>)),
new ToolboxItemWrapper(typeof(While)),
};
ToolboxCategory categoryTransaction = new ToolboxCategory("Transaction")
{
new ToolboxItemWrapper(typeof(CancellationScope)),
new ToolboxItemWrapper(typeof(CompensableActivity)),
new ToolboxItemWrapper(typeof(Compensate)),
new ToolboxItemWrapper(typeof(Confirm)),
new ToolboxItemWrapper(typeof(TransactionScope)),
};
ToolboxCategory categoryErrorHandling = new ToolboxCategory("Error Handling")
{
new ToolboxItemWrapper(typeof(Rethrow)),
new ToolboxItemWrapper(typeof(Throw)),
new ToolboxItemWrapper(typeof(TryCatch)),
};
#endregion
ctrl.Categories.Add(categoryPrimitives);
ctrl.Categories.Add(categoryControlFlow);
ctrl.Categories.Add(categoryErrorHandling);
ctrl.Categories.Add(categoryFlowchart);
ctrl.Categories.Add(categoryTransaction);
ctrl.Categories.Add(categoryCollection);
return ctrl;
}
}
}
窗口引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Presentation;
using System.Activities.Presentation.Hosting;
using System.Windows;
using System.Windows.Controls;
using System.Activities.Presentation.Toolbox;
using System.Activities.Statements;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
factory.RegisterMetadata();
elementHost1.Child = factory.LoadToolBox();
elementHost2.Child = factory.LoadDesigner("");
elementHost3.Child = factory.LoadPropertyInspector();
}
private factory factory = new factory();
}
}
效果: