技术开发 频道

详解Visual Studio 2010中的活动设计器

  (5)从Workflow 模板选择Activity Designer 并将之取名文为PrePostSequenceDesigner


添加PrePostSequenceDesigner activity designer

  (6)将模板中的XAML文件替换成以下内容

  (代码段- Introduction to WF4 Lab – PrePostSequenceDesigner XAML CSharp)

  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">

  Activities

  (代码段
- Introduction to WF4 Lab – PrePostSequenceDesigner XAML VB)

  XAML (VB)

  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">

  Item
="{Binding Path=ModelItem.Pre, Mode=TwoWay}"

  HintText
="Insert Pre Activities Here"/>

  BorderThickness
="2" CornerRadius="5">

  HorizontalAlignment
="Center">Activities

  Items
="{Binding Path=ModelItem.Activities}"

  HintText
="Insert Activities Here">

  WorkflowItemPresenter
/ WorkflowItemsPresenter

 

  我们的自定义设计器使用databinding来绑定到PrePostSequence类的属性。 Pre和Post属性是单一的活动,所以自定义设计器使用WorkflowItemPresenter将它们呈现在设计器表面。

  活动集合使用WorkflowItemsPresenter来创建设计器表面,它可以包含一个活动的集合。

  (7)按CTRL+SHIFT+B来编译解决方案

  5.将活动设计器与活动练习起来

  现在我们有了一个活动设计器,但除非将它与自定义活动练习起来,它才能发挥作用。

  (1)右击HelloWorkflow.Activities项目并选择Add Reference…

  (2)从projects tab加入对HelloWorkflow.Activities.Designers的引用

  (3)再一次选择Add Reference,并从.NET tab里加入对以下程序集的引用

  ·System.Activities.Presentation

  ·PresentationFramework

  ·PresentationCore

  ·WindowsBase

  (4)打开PrePostSequence.cs (C#)或PrePostSequence.vb (VB),并加入以下命名空间

  using System.ComponentModel;

  
using HelloWorkflow.Activities.Designers;
  Imports System.ComponentModel

  
Imports HelloWorkflow.Activities.Designers

 

  (5)在PrePostSequence类上添加以下属性.

  [Designer(typeof(PrePostSequenceDesigner))]

  
public sealed class PrePostSequence : NativeActivity

 

  Visual Basic

  
Public NotInheritable Class PrePostSequence

 

0
相关文章