自定义Activity.docx

上传人:scccc 文档编号:13211460 上传时间:2021-12-18 格式:DOCX 页数:15 大小:271.28KB
返回 下载 相关 举报
自定义Activity.docx_第1页
第1页 / 共15页
自定义Activity.docx_第2页
第2页 / 共15页
自定义Activity.docx_第3页
第3页 / 共15页
自定义Activity.docx_第4页
第4页 / 共15页
自定义Activity.docx_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《自定义Activity.docx》由会员分享,可在线阅读,更多相关《自定义Activity.docx(15页珍藏版)》请在三一文库上搜索。

1、.1 自定义Activity说明自定义Activity1.可以从System.Workflow.Activities.SequenceActivity继承,从SequenceActivity派生的类,将不能实现 IActivityEventListener 接口.或不能被正确执行2.可以从System.Workflow.ComponentModel.Activity继承3.可以从System.Workflow.ComponentModel.CompositeActivity继承4.可以从System.Workflow.Activities.StateActivity继承5.以下系统提供的Act

2、ivity可以继承System.Workflow.Activities.CallExternalMethodActivitySystem.Workflow.Activities.HandleExternalEventActivity6.使用设计器创建Activity默认从System.Workflow.Activities.SequenceActivity继承从SequenceActivity派生的类,将不能实现 IActivityEventListener 接口.或不能被正确执行2 从System.Workflow.ComponentModel.Activity继承定义using Syste

3、m.Workflow.ComponentModel;using System.ComponentModel;public class wxdActivity : System.Workflow.ComponentModel.Activity public wxdActivity() InitializeComponent(); System.Diagnostics.DebuggerNonUserCode private void InitializeComponent() this.Name = "wxd" /自定义事件,开始执行理 public event System.

4、EventHandler wxdBeginEnent; /自定义事件,执行完成时 public event System.EventHandler wxdEndEvent; /自定义属性public static DependencyProperty wxdValueProperty = DependencyProperty.Register("wxdValue", typeof(string), typeof(wxdActivity); Browsable(true) DesignerSerializationVisibility(DesignerSerializatio

5、nVisibility.Visible) public string wxdValue get return (string)(base.GetValue(wxdActivity.wxdValueProperty); set base.SetValue(wxdActivity.wxdValueProperty, value); /override Activity的Execute方法 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) wxdBeginEnen

6、t(null, null); System.Console.WriteLine(this.Parent.Name); System.Console.WriteLine(this.wxdValue); wxdEndEvent(null, null); return base.Execute(executionContext); / executionContext /执行上下文对象 使用3 使用3.1 为Activity添加图标在类前添加 System.Drawing.ToolboxBitmap(typeof(wxdActivity), "wxd.bmp") public c

7、lass wxdActivity : System.Workflow.ComponentModel.Activity3.2 为Activity设置外观 /设计器样式类 ActivityDesignerThemeAttribute(typeof(wxdTheme) public class wxdActivityDesigner : ActivityDesigner /主题类 public class wxdTheme : ActivityDesignerTheme public wxdTheme(WorkflowTheme theme) : base(theme) this.BorderCol

8、or = Color.Red; /边框色 this.BorderStyle = DashStyle.Dash ; /边框线条 this.BackColorStart = Color.White; /渐变开始色 this.BackColorEnd = Color.Blue; /渐变结束色 this.BackgroundStyle = LinearGradientMode.ForwardDiagonal;/渐变方向 Designer(typeof(wxdActivityDesigner), typeof(IDesigner)public class wxdActivity : System.Wor

9、kflow.ComponentModel.Activity如果在继承了SequenceActivity的Activity使用了上面的主题,可以使用其内部Activity不显示Designer(typeof(wxdActivityDesigner), typeof(IDesigner)public partial class Activity1: SequenceActivity3.3 为Activity添加菜单using System.Workflow.ComponentModel;using System.ComponentModel;using System.Workflow.Compon

10、entModel.Design;using System.Drawing;using System.Drawing.Drawing2D;using System.ComponentModel.Design;using System;using System.Collections.Generic;namespace wxwinter /自定义Activity Designer(typeof(wxdActivityDesigner), typeof(IDesigner) public class wxdActivity : System.Workflow.ComponentModel.Activ

11、ity public static DependencyProperty wxdValueProperty = DependencyProperty.Register("wxdValue", typeof(string), typeof(wxdActivity); Browsable(true) DesignerSerializationVisibility(DesignerSerializationVisibility.Visible) public string wxdValue get return (string)(base.GetValue(wxdActivity

12、.wxdValueProperty); set base.SetValue(wxdActivity.wxdValueProperty, value); /自定义设计器 public class wxdActivityDesigner : ActivityDesigner protected override System.Collections.ObjectModel.ReadOnlyCollection<DesignerAction> DesignerActions get List<DesignerAction> list = new List<Designe

13、rAction>(); foreach (DesignerAction temp in base.DesignerActions) list.Add(new DesignerAction(this, temp.ActionId, temp.Text); return list.AsReadOnly(); protected override ActivityDesignerVerbCollection Verbs get ActivityDesignerVerbCollection NewVerbs = new ActivityDesignerVerbCollection(); NewV

14、erbs.AddRange(base.Verbs); ActivityDesignerVerb menu = new ActivityDesignerVerb(this, DesignerVerbGroup.View, "设置wxdValue", new EventHandler(menu_click); NewVerbs.Add(menu); return NewVerbs; /当添加的菜单单击时要执行的操作 private void menu_click(object sender, EventArgs e) using (wxdSetForm wf = new wxd

15、SetForm() string v = (string)this.Activity.GetValue(wxdActivity.wxdValueProperty); wf.Value = v; wf.ShowDialog(); this.Activity.SetValue(wxdActivity.wxdValueProperty,wf.Value); /自定义数据设置窗体 public class wxdSetForm : System.Windows.Forms.Form public string Value; System.Windows.Forms.TextBox tx = new S

16、ystem.Windows.Forms.TextBox(); System.Windows.Forms.Button bt = new System.Windows.Forms.Button(); public wxdSetForm() bt.Top=30; this.Controls.Add(tx); this.Controls.Add(bt); bt.Click += new EventHandler(bt_Click); bt.Text = "确定" this.Load += new EventHandler(wxdSetForm_Load); void wxdSet

17、Form_Load(object sender, EventArgs e) this.tx.Text = Value; void bt_Click(object sender, EventArgs e) this.Value = this.tx.Text; this.Hide(); 在自定义的设计器中也可以使用3.4 为Activity添加属性验证器using System.Workflow.ComponentModel;using System.ComponentModel;using System.Workflow.ComponentModel.Design;using System.Dr

18、awing;using System.Drawing.Drawing2D;using System.ComponentModel.Design;using System;using System.Collections.Generic;using System.Workflow.ComponentModel.Compiler;namespace wxwinter /自定义Activity ActivityValidator(typeof(wxdActivityValidator) public class wxdActivity : System.Workflow.ComponentModel

19、.Activity public static DependencyProperty wxdValueProperty = DependencyProperty.Register("wxdValue", typeof(string), typeof(wxdActivity); Browsable(true) DesignerSerializationVisibility(DesignerSerializationVisibility.Visible) public string wxdValue get return (string)(base.GetValue(wxdAc

20、tivity.wxdValueProperty); set base.SetValue(wxdActivity.wxdValueProperty, value); /验证器类 public class wxdActivityValidator : System.Workflow.ComponentModel.Compiler.ActivityValidator public override ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj) ValidationErrorCol

21、lection Errors = base.ValidateProperties(manager, obj); if (obj != null) this.wxdValueValidator(Errors, (wxdActivity)obj); return Errors; private void wxdValueValidator(ValidationErrorCollection Errors, wxdActivity obj) if (obj.wxdValue="") Errors.Add(ValidationError.GetNotSetValidationError(wxdActivity.wxdValueProperty.Name); *;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1