We will create the Toolbox and Property Inspector windows, and add
them to the Workflow Designer.
- From last post create the Toolbox and
include it in the WPF grid. To do this, in Solution Explorer right-click the MainWindow.xaml file and choose View Code. Modify the code by following these steps:a. Add a factory method named GetToolboxControl that creates a ToolboxControl, adds a Toolbox Category Items Collection named category1 inside it, and assigns two items to it:
¨ CustomActivities.Prompt activity.
¨ System.Activities.Statements.Sequence activity.
C#
private ToolboxControl GetToolboxControl(){//Create the ToolBoxControlToolboxControl ctrl = new ToolboxControl();//Create a collection of category itemsToolboxCategory categoryItems = new ToolboxCategory("category1");//Creating toolboxItemsToolboxItemWrapper tool =new ToolboxItemWrapper("CustomActivities.Prompt","CustomActivities", null, null);ToolboxItemWrapper tool2 = new ToolboxItemWrapper("System.Activities.Statements.Sequence","System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",null, "Sequence");//Adding the toolboxItems to the category.categoryItems.Add(tool);categoryItems.Add(tool2);//Adding the category to the ToolBox control.ctrl.Categories.Add(categoryItems);return ctrl;}
Visual Basic
Private Function GetToolboxControl() As
ToolboxControl
' Create the ToolBoxControl
Dim ctrl As New ToolboxControl()
' Create a collection of categories
Dim categoryItems As New ToolboxCategory("category1")
' Creating toolboxItems
Dim tool As New ToolboxItemWrapper("CustomActivities.Prompt", "CustomActivities", Nothing, Nothing)
Dim tool2 As New ToolboxItemWrapper("System.Activities.Statements.Sequence",
"System.Activities, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35", Nothing, "Sequence")
'Adding the toolboxItems to the category.
categoryItems.Add(tool)
categoryItems.Add(tool2)
'Adding the category to the ToolBox control.
ctrl.Categories.Add(categoryItems)
Return ctrl
End Function
b. Place the Toolbox control
to the leftmost column of the WPF grid. To do this, add a private method AddToolbox to the MainWindow class.
C#
private void AddToolBox()
{
ToolboxControl tc = GetToolboxControl();
Grid.SetColumn(tc, 0);
grid1.Children.Add(tc);
}
Visual Basic
Private Sub AddToolBox()
Dim tc As ToolboxControl = GetToolboxControl()
Grid.SetColumn(tc, 0)
grid1.Children.Add(tc)
End Sub
c. Add a call to the AddToolbox
method created in the previous step. To do this, add the following code (shown
in bold) to the MainWindow class constructor.
C#
public MainWindow()
{
InitializeComponent();
this.RegisterMetadata();
this.AddDesigner();
this.AddToolBox();
}
Visual Basic
Public Sub New()
InitializeComponent()
Me.RegisterMetadata()
Me.AddDesigner()
Me.AddToolBox()
End Sub
d. Press CTRL+S to save
the changes.
2. Press CTRL+F5 to
build and run the solution and verify that the toolbox is created in the
leftmost column of the application window and that items dragged from the
toolbox can be dropped on the Workflow
Designer surface.
The WPF application hosting the WorkflowDesigner and the Toolbox
|
No comments:
Post a Comment