WF4.0 应用篇(四) IActivityToolboxService 自动化工具栏

 

WF4.0 应用篇(四) IActivityToolboxService 自动化工具栏

例子下载: https://files.cnblogs.com/foundation/IActivityToolboxServiceSample.rar

 

 

System.Activities.Presentation.IActivityToolboxService

 

在设计工作流的创时,

可以实现工具栏的上下文相关

如当一个Activity被添加到工作流中后,会自动在工具栏中显示与该Activity相关的Activity

当这个Activity从工作流中移除时,会自动在工具栏中隐藏相关的Activity

 

实现思路如下:

1.为Activity添加一个Designer

2.override Designer的 OnModelItemChanged方法

3.在 OnModelItemChanged方法内用IActivityToolboxService向工具栏添加关联的Activity

4.关联Activity的移除是自动完成的,不用代码

 

 

定义[myActivity],[myActivityOne],[myActivityTwo]

 

当向流程中添加[myActivity]时[myActivityOne],[myActivityTwo]自动出现在工具栏中

当这个[myActivity]从工作流中移除时,会自动在工具栏中隐藏[myActivityOne],[myActivityTwo]

 

myActivityOne

myActivityTwo

任意

myActivity

[System.ComponentModel.Designer(typeof(myActivityDesigner))]

public sealed class myActivity : CodeActivity

{

 

public InArgument<string> Text { get; set; }

 

protected override void Execute(CodeActivityContext context)

{

string text = context.GetValue(this.Text);

}

}

myActivityDesigner

<sap:ActivityDesigner x:Class="IActivityToolboxServiceSample.myActivityDesigner"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"

xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">

<Grid>

 

</Grid>

</sap:ActivityDesigner>

public partial class myActivityDesigner

{

public myActivityDesigner()

{

InitializeComponent();

}

 

protected override void OnModelItemChanged(object newItem)

{

 

base.OnModelItemChanged(newItem);

System.Activities.Presentation.IActivityToolboxService toolboxService = (System.Activities.Presentation.IActivityToolboxService)this.Context.Services.GetService(typeof(System.Activities.Presentation.IActivityToolboxService));

 

toolboxService.AddCategory("myActivity自定义选卡");

toolboxService.AddItem("IActivityToolboxServiceSample.myActivityOne,IActivityToolboxServiceSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

, "myActivity自定义选卡");

oolboxService.AddItem("IActivityToolboxServiceSample.myActivityTwo,IActivityToolboxServiceSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

, "myActivity自定义选卡");

}

}

IActivityToolboxServiceSample.myActivityOne,IActivityToolboxServiceSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

的查看

 

使用

posted @ 2010-05-13 10:59  WXWinter(冬)  阅读(2486)  评论(5编辑  收藏  举报