Public partial class Window1: Window
{
Public Window1 ()
{
InitializeComponent ();
}
WorkflowDesigner designer;
Private void StackPanel_Loaded (object sender, RoutedEventArgs e)
{
ToolboxCategoryItemsCollection toolList = new ToolboxCategoryItemsCollection ("basic tools ");
Toolbox. Categories. Add (toolList );
ToolList. Add (new ToolboxItemWrapper (typeof (node <myData>), "Node "));
ToolList. Add (new ToolboxItemWrapper (typeof (System. Activities. Statements. FlowSwitch), "branch "));
ToolList. Add (new ToolboxItemWrapper (typeof (System. Activities. Statements. WriteLine), "output "));
// ======
DesignerMetadata dm = new DesignerMetadata ();
Dm. Register ();
//-
AttributeTableBuilder builder = new AttributeTableBuilder ();
Builder. AddCustomAttributes (typeof (node <myData>), new DesignerAttribute (typeof (myDesigner )));
MetadataStore. AddAttributeTable (builder. CreateTable ());
// ==============
Designer = new WorkflowDesigner ();
Var root = new System. Activities. Statements. Flowchart ();
Var v = new System. Activities. Variable <myData> ();
V. Name = "content ";
V. Default = new myData ();
Root. Variables. Add (v );
Designer. Load (root );
DesienerPanel. Content = designer. View;
PropertyPanel. Children. Add (designer. PropertyInspectorView );
}
WorkflowInstance myInstance;
Public WorkflowInstance createInstanceFromXamlString (string xaml)
{
System. Text. UTF8Encoding utf8 = new System. Text. UTF8Encoding ();
Byte [] bs = utf8.GetBytes (xaml );
System. IO. MemoryStream memoryStream = new System. IO. MemoryStream (bs );
WorkflowElement activity = WorkflowXamlServices. Load (memoryStream );
WorkflowInstance myInstance = new WorkflowInstance (activity );
Return myInstance;
}
Private void Button_Click (object sender, RoutedEventArgs e)
{
System. Console. Clear ();
MyInstance = createInstanceFromXamlString (designer. Text );
MyInstance. OnCompleted = delegate (WorkflowCompletedEventArgs ee) {System. Console. WriteLine ("end ");};
MyInstance. Run ();
}
Private void yes_Click (object sender, RoutedEventArgs e)
{
MyData date = new myData ();
Date. Result = "";
Date. Description = tb. Text;
MyInstance. ResumeBookmark ("mywait", date );
}
Private void nextUser_Click (object sender, RoutedEventArgs e)
{
MyData date = new myData ();
Date. Result = "B ";
Date. Description = tb. Text;
MyInstance. ResumeBookmark ("mywait", date );
}
} |