Workflow 设计器上的工作流基础本机活动子活动
我创建的本机活动如下所示:Workflow 设计器上的工作流基础本机活动子活动,workflow,workflow-foundation-4,workflow-foundation,workflow-foundation-4.5,Workflow,Workflow Foundation 4,Workflow Foundation,Workflow Foundation 4.5,我创建的本机活动如下所示: public sealed class ConsoleColorScope : NativeActivity { #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="ConsoleColorScope"/> class. //
public sealed class ConsoleColorScope : NativeActivity
{
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleColorScope"/> class.
/// </summary>
public ConsoleColorScope()
{
this.Color = ConsoleColor.Gray;
}
#endregion
#region Public Properties
/// <summary>
/// Gets or sets Body.
/// </summary>
[DefaultValue(null)]
public Activity Body { get; set; }
/// <summary>
/// Gets or sets Color.
/// </summary>
public ConsoleColor Color { get; set; }
#endregion
#region Methods
/// <summary>
/// The execute.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
protected override void Execute(NativeActivityContext context)
{
context.Properties.Add(ConsoleColorProperty.Name, new ConsoleColorProperty(this.Color));
if (this.Body != null)
{
context.ScheduleActivity(this.Body);
}
}
#endregion
/// <summary>
/// The console color property.
/// </summary>
private class ConsoleColorProperty : IExecutionProperty
{
#region Constants and Fields
/// <summary>
/// The name.
/// </summary>
public const string Name = "ConsoleColorProperty";
/// <summary>
/// The color.
/// </summary>
private readonly ConsoleColor color;
/// <summary>
/// The original.
/// </summary>
private ConsoleColor original;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleColorProperty"/> class.
/// </summary>
/// <param name="color">
/// The color.
/// </param>
public ConsoleColorProperty(ConsoleColor color)
{
this.color = color;
}
#endregion
#region Explicit Interface Methods
/// <summary>
/// Cleanup the workflow thread.
/// </summary>
void IExecutionProperty.CleanupWorkflowThread()
{
Console.ForegroundColor = this.original;
}
/// <summary>
/// Setup the workflow thread.
/// </summary>
void IExecutionProperty.SetupWorkflowThread()
{
this.original = Console.ForegroundColor;
Console.ForegroundColor = this.color;
}
#endregion
}
}
公共密封类控制台颜色范围:NativeActivity
{
#区域构造函数和析构函数
///
///初始化类的新实例。
///
公共控制台彩色示波器()
{
this.Color=ConsoleColor.Gray;
}
#端区
#区域公共财产
///
///获取或设置正文。
///
[默认值(空)]
公共活动主体{get;set;}
///
///获取或设置颜色。
///
公共控制台颜色{get;set;}
#端区
#区域方法
///
///执行。
///
///
///上下文。
///
受保护的覆盖无效执行(NativeActivityContext上下文)
{
添加(ConsoleColorProperty.Name,新的ConsoleColorProperty(this.Color));
如果(this.Body!=null)
{
context.ScheduleActivity(this.Body);
}
}
#端区
///
///控制台颜色属性。
///
私有类ConsoleColor属性:IEExecutionProperty
{
#区域常数和字段
///
///名字。
///
public const string Name=“ConsoleColorProperty”;
///
///颜色。
///
专用只读控制台颜色;
///
///原著。
///
私人控制台颜色原件;
#端区
#区域构造函数和析构函数
///
///初始化类的新实例。
///
///
///颜色。
///
公共控制台颜色属性(控制台颜色)
{
这个颜色=颜色;
}
#端区
#区域显式接口方法
///
///清理工作流线程。
///
void IExecutionProperty.cleanuwWorkflowThread()
{
Console.ForegroundColor=this.original;
}
///
///设置工作流线程。
///
void IExecutionProperty.SetupWorkflowThread()
{
this.original=Console.ForegroundColor;
Console.ForegroundColor=this.color;
}
#端区
}
}
这是从工作示例中获取的类:
然而,当我打开XAML文件时,我无法看到范围内的子活动,如上面链接上的图片所示。我只能看到作用域的名称
我已经创造了我自己版本的NativeActivity,我也有同样的问题。是否有一些我必须遵循的程序可以让我看到NativeActivity的主体,我可以在其中拖放其他活动(类似于序列活动),如演示说明所示?您需要创建一个活动设计器项目,以便与具有拖放区的自定义活动一起进行(一个
WorkflowItemPresenter
控件),用于放置活动以填充自定义活动的主体属性。然后可以设置管道以将设计器链接到活动。以下详细说明了步骤
创建新的活动设计器项目
在解决方案中,添加名为like.Design
的新活动设计器项目。程序集必须命名为.Design.dll
,以便Visual Studio将活动设计器用于自定义活动。在设计器的XAML中,您将使用WorkflowItemPresenter
来显示接受自定义活动的用户可以使用的活动
<sap:ActivityDesigner x:Class="Your_Custom_Activity_Library.Design.ConsoleColorScopeDesigner"
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>
<sap:WorkflowItemPresenter HintText="Drop an activity here!"
Item="{Binding Path=ModelItem.Body, Mode=TwoWay}"
MinWidth="300"
MinHeight="150" />
</Grid>
</sap:ActivityDesigner>
Visual Studio加载自定义活动设计器的方法是查找名为.Design.dll
的程序集,然后查找实现IRegisterMetadata
接口的公共类
现在,您应该能够将自定义活动拖放到工作流中,它将具有一个拖放区域,允许您指定主体
活动
您可以喜欢您的设计器,并公开友好的控件以允许用户设置自定义活动。您还可以为.NET Framework中提供的开箱即用活动创建自己的设计器
希望对您有所帮助。您需要创建一个活动设计器项目,以配合您的自定义活动,该活动有一个放置区域(一个
WorkflowItemPresenter
控件)用于放置活动以填充自定义活动的主体属性。然后,您可以设置管道以将设计器链接到活动。以下详细说明了这些步骤
创建新的活动设计器项目
在解决方案中,添加名为like.Design
的新活动设计器项目。程序集必须命名为.Design.dll
,以便Visual Studio将活动设计器用于自定义活动。在设计器的XAML中,您将使用WorkflowItemPresenter
来显示接受自定义活动的用户可以使用的活动
<sap:ActivityDesigner x:Class="Your_Custom_Activity_Library.Design.ConsoleColorScopeDesigner"
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>
<sap:WorkflowItemPresenter HintText="Drop an activity here!"
Item="{Binding Path=ModelItem.Body, Mode=TwoWay}"
MinWidth="300"
MinHeight="150" />
</Grid>
</sap:ActivityDesigner>
Visual Studio加载自定义活动设计器的方法是查找名为.Design.dll
的程序集,然后查找实现IRegisterMetadata
接口的公共类
现在,您应该能够将自定义活动拖放到工作流中,它将具有一个拖放区域,允许您指定主体
活动
你可以喜欢你的设计器,并公开友好的控件,允许用户设置你的自定义活动