技术开发 频道

详解Visual Studio中的移植设计器功能

  如下面所示, RegisterMetadata函数 使得设计器能够储存元数据。

  (代码段- Introduction to WF4 Lab – RegisterMetadata method CSharp)

private void RegisterMetadata()
{
    DesignerMetadata metaData
= new DesignerMetadata();
    metaData.Register();
    AttributeTableBuilder builder
= new AttributeTableBuilder();
    MetadataStore.AddAttributeTable(builder.CreateTable());
}

 

  (代码段- Introduction to WF4 Lab – RegisterMetadata method VB)

Public Sub RegisterMetadata()
    
Dim metaData As DesignerMetadata = New DesignerMetadata()
    metaData.Register()
    
Dim builder As AttributeTableBuilder = New AttributeTableBuilder()
    MetadataStore.AddAttributeTable(builder.CreateTable())
End Sub

  当你移植设计器,你可以控制工具栏。你可以选择出现在工具栏上的控件,该控件的分类,甚至控件的名称。如下面所示,CreateToolboxControl函数实现了上述功能。

  (代码段- Introduction to WF4 Lab – CreateToolboxControl method CSharp)

private ToolboxControl CreateToolboxControl()
{
    
//Create the ToolBoxControl
    ToolboxControl ctrl = new ToolboxControl();

    
//Create a collection of category items
    ToolboxCategory category = new ToolboxCategory("Hello Workflow");

    
//Creating toolboxItems
    ToolboxItemWrapper tool0 = new ToolboxItemWrapper(
        
"System.Activities.Statements.Assign",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        ,
null,
        
"Assign");
    ToolboxItemWrapper tool1
= new ToolboxItemWrapper(
        
"System.Activities.Statements.Sequence",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
        
null,
        
"Sequence");
    ToolboxItemWrapper tool2
= new ToolboxItemWrapper(
        
"System.Activities.Statements.TryCatch",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
        
null,
        
"Try It"); // Can use a different name
    ToolboxItemWrapper tool3 = new ToolboxItemWrapper(
        
"HelloWorkflow.Activities.PrePostSequence",
        
"HelloWorkflow.Activities",
        
null,
        
"PrePostSequence");

    
//Adding the toolboxItems to the category.
    category.Add(tool0);
    category.Add(tool1);
    category.Add(tool2);
    category.Add(tool3);

    
//Adding the category to the ToolBox control.
    ctrl.Categories.Add(category);
    
return ctrl;
}

   (代码段- Introduction to WF4 Lab – CreateToolboxControl method VB)

Private Function CreateToolboxControl() As ToolboxControl
    
'Create the ToolBoxControl
    Dim ctrl As ToolboxControl = New ToolboxControl()

    
'Create a collection of category items
    Dim category As ToolboxCategory = New ToolboxCategory("Hello Workflow")

    
'Creating toolboxItems
    Dim tool0 As ToolboxItemWrapper = New ToolboxItemWrapper(
        
"System.Activities.Statements.Assign",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
        
Nothing,
        
"Assign")
    
Dim tool1 As ToolboxItemWrapper = New ToolboxItemWrapper(
        
"System.Activities.Statements.Sequence",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
        
Nothing,
        
"Sequence")
    
Dim tool2 As ToolboxItemWrapper = New ToolboxItemWrapper(
        
"System.Activities.Statements.TryCatch",
        
"System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
        
Nothing,
        
"Try It") ' Can use a different name
    Dim tool3 As ToolboxItemWrapper = New ToolboxItemWrapper(
        
"HelloWorkflow.Activities.PrePostSequence",
        
"HelloWorkflow.Activities",
        
Nothing,
        
"PrePostSequence")

    
'Adding the toolboxItems to the category.
    category.Add(tool0)
    category.Add(tool1)
    category.Add(tool2)
    category.Add(tool3)

    
'Adding the category to the ToolBox control.
    ctrl.Categories.Add(category)
    
Return ctrl
End Function

 

0
相关文章