- Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
- Open the project from last post Building a Composite Activity Designer part(2 - 4) .
- Register
the PrePostSequence and TryCatch designers in the Workflow Designer metadata. To do this,
in Solution Explorer, under the HostingApplication project, right-click
MainWindow.xaml and select View Code. In the RegisterMetadata method add the following code (shown in bold):C#private void RegisterMetadata(){(new DesignerMetadata()).Register();AttributeTableBuilder builder = new AttributeTableBuilder();// Register Custom Designers.builder.AddCustomAttributes(typeof(Prompt), new DesignerAttribute(typeof(BasicDesignerWithStyling)));builder.AddCustomAttributes(typeof(PrePostSequence), new DesignerAttribute(typeof(PrePostSequenceDesigner)));builder.AddCustomAttributes(typeof(TryCatch), new DesignerAttribute(typeof(MyTryCatchFinally)));// Apply the metadataMetadataStore.AddAttributeTable(builder.CreateTable());}Visual BasicPrivate Sub RegisterMetadata()Dim dm As New DesignerMetadata()dm.Register()Dim builder As New AttributeTableBuilder()' Register Custom Designers.builder.AddCustomAttributes(GetType(Prompt), New DesignerAttribute(GetType(BasicDesignerWithStyling)))builder.AddCustomAttributes(GetType(PrePostSequence), New DesignerAttribute(GetType(PrePostSequenceDesigner)))builder.AddCustomAttributes(GetType(TryCatch), New DesignerAttribute(GetType(MyTryCatchFinally)))' Apply the metadataMetadataStore.AddAttributeTable(builder.CreateTable())End SubNote: Doing this you are overriding the default TryCatch designer with the custom one created in the previous post.
- Create
two new toolbox items for each activity, and register them in the designer
Toolbox. To do this, find the GetToolboxControl
method and add the following code (shown in bold):C#private ToolboxControl GetToolboxControl(){//Create the ToolBoxControlToolboxControl ctrl = new ToolboxControl();//Create a collection of categoriesToolboxCategory 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");ToolboxItemWrapper tool3 = new ToolboxItemWrapper("System.Activities.Statements.TryCatch", "System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", null, "MyTryCatchFinally");ToolboxItemWrapper tool4 = new ToolboxItemWrapper("CustomActivities.PrePostSequence", "CustomActivities", null, "PrePostSequence");categoryItems.Add(tool);categoryItems.Add(tool2);categoryItems.Add(tool3);categoryItems.Add(tool4);ctrl.Categories.Add(categoryItems);return ctrl;}Visual BasicPrivate Function GetToolboxControl() As ToolboxControl' Create the ToolBoxControlDim ctrl As New ToolboxControl()' Create a collection of categoriesDim categoryItems As New ToolboxCategory("category1")'Creating toolboxItemsDim 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")Dim tool3 As New ToolboxItemWrapper("System.Activities.Statements.TryCatch", "System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", Nothing, "MyTryCatchFinally")Dim tool4 As New ToolboxItemWrapper("CustomActivities.PrePostSequence", "CustomActivities", Nothing, "PrePostSequence")categoryItems.Add(tool)categoryItems.Add(tool2)categoryItems.Add(tool3)categoryItems.Add(tool4)ctrl.Categories.Add(categoryItems)Return ctrlEnd Function
10/08/2012
Building a Composite Activity Designer part(3 - 4)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment