0
我有一个解决方案,它定义了一个自定义活动,并且我让一个设计师跟着它(见下文)。我有3个项目,一个用于自定义活动,一个用于自定义活动的设计器,第三个用于实际运行我的自定义活动(一个简单的控制台应用程序)。VS2010自定义活动设计器未被使用
当我创建一个使用我的自定义活动的组合活动时,VS中的设计器不使用我的自定义设计器。我确保设计器程序集以* .Design.dll名称命名,并且它被复制到控制台应用程序的bin目录中,但无法弄清楚为什么它没有选择我的自定义设计器。有任何想法吗?以下是所有必要部件的代码。
我的自定义活动
namespace WorkflowSampler.Activities
{
using System.Activities;
using System.Diagnostics;
public class SampleVarChanger : NativeActivity
{
private InArgument<int> expressionToEvaluate;
private Variable<int> counter;
public Variable<int> Counter
{
get
{
return this.counter ?? (this.counter = new Variable<int>());
}
set
{
this.counter = value;
}
}
public InArgument<int> ExpressionToEvaluate
{
get
{
return this.expressionToEvaluate ?? (this.expressionToEvaluate = new InArgument<int>());
}
set
{
this.expressionToEvaluate = value;
}
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
metadata.AddImplementationVariable(this.Counter);
var exprToEvalRuntimeArg = new RuntimeArgument("ExpressionToEvaluate", typeof(int), ArgumentDirection.In);
metadata.Bind(this.ExpressionToEvaluate, exprToEvalRuntimeArg);
metadata.AddArgument(exprToEvalRuntimeArg);
}
protected override void Execute(NativeActivityContext context)
{
Debug.WriteLine(string.Format("Counter Variable Value: {0}", this.Counter.Get(context)));
}
}
}
我的自定义活动的设计师(XAML部分)
<sap:ActivityDesigner x:Class="WorkflowSampler.Activities.Design.SampleVarChangerDesigner"
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"
xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation">
<sap:ActivityDesigner.Resources>
<ResourceDictionary>
<sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
</ResourceDictionary>
</sap:ActivityDesigner.Resources>
<Grid Margin="10, 0, 0, 0">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<TextBlock Text="Variable Name:" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" />
<TextBox Name="VariableName" VerticalContentAlignment="Center" Grid.Row="0" Grid.Column="1" TextChanged="OnVariableNameChanged" />
<TextBlock Text="Expression Using Variable:" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" />
<sapv:ExpressionTextBox Name="ExpressionUsingVariable" VerticalContentAlignment="Center" Expression="{Binding Path=ModelItem.ExpressionToEvaluate, Converter={StaticResource ResourceKey=ArgumentToExpressionConverter}, ConverterParameter=In, Mode=TwoWay}" OwnerActivity="ModelItem" Grid.Row="1" Grid.Column="1" />
</Grid>
</sap:ActivityDesigner>
我的自定义活动的设计(代码部分之后)
namespace WorkflowSampler.Activities.Design
{
using System.Activities;
// Interaction logic for SampleVarChangerDesigner.xaml
public partial class SampleVarChangerDesigner
{
public SampleVarChangerDesigner()
{
InitializeComponent();
}
private void OnVariableNameChanged(object sender, TextChangedEventArgs e)
{
this.ModelItem.Properties["Counter"].SetValue(new Variable<int>(this.VariableName.Text));
}
}
}
的IRegisterMetadata接口需要VS设计器支持
namespace WorkflowSampler.Activities.Design
{
using System.Activities.Presentation.Metadata;
using System.ComponentModel;
/// <summary>
/// Registers the activity designer metadata.
/// </summary>
public class RegisterMetadata : IRegisterMetadata
{
public void Register()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(SampleVarChanger), new DesignerAttribute(typeof(SampleVarChangerDesigner)));
MetadataStore.AddAttributeTable(builder.CreateTable());
}
}
}
它不适合我,它真的很让人沮丧,因为有来自visual studio的ZERO输出让我知道发生了什么问题。 – Aaron 2016-05-17 16:42:57
需要尝试的一件事是实际删除[obj]文件夹以清除VS可能保留的任何缓存项目,从而防止实际使用设计器。 我的确同意,由于其工作方式,在诊断WF问题方面几乎没有什么信息可以继续。自定义设计师体验绝对可以在VS中使用更新。 – ajawad987 2016-05-18 14:48:06
我在这里遇到你的帖子几次后,我确实设法弄清楚了。显然有很多事情我不得不做,而后构建事件只是其中之一。他们真的需要让这件事更直接。 – Aaron 2016-05-18 15:00:37