【发布时间】:2013-02-01 18:47:16
【问题描述】:
我在 Workflow Foundation 中使用自定义活动和设计器时遇到问题。为了这个问题,我创建了一个非常简单的活动,如下所示:
[Designer(typeof(TesteDesigner))]
public sealed class Teste : CodeActivity
{
// Define an activity input argument of type string
[RequiredArgument]
public InArgument<string> Text { get; set; }
// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext context)
{
// Obtain the runtime value of the Text input argument
string text = context.GetValue(this.Text);
}
}
而设计者如下:
<sap:ActivityDesigner x:Class="ActivityDesignerLibrary1.TesteDesigner"
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:System="clr-namespace:System;assembly=mscorlib"
xmlns:Converters="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation">
<sap:ActivityDesigner.Resources>
<Converters:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
</sap:ActivityDesigner.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="Valor: "
VerticalAlignment="Center" />
<sapv:ExpressionTextBox HintText="Valor"
Expression="{Binding Path=ModelItem.Text, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
ExpressionType="{x:Type System:String}"
OwnerActivity="{Binding Path=ModelItem}"
UseLocationExpression="True"
Grid.Column="1"
Margin="3,0,0,0" />
</Grid>
</sap:ActivityDesigner>
当我在 TextBox 中输入内容时,我得到一个错误:invalid l-value expression,但如果我在属性网格上输入值,TextBox 会更新。
有人见过吗?
谢谢。
【问题讨论】:
-
您确定您的 SSCCE 是正确的?就目前而言,在设计时,
Text将是 null,这可能会导致ArgumentToExpressionConverter在第一次运行时出现问题。尝试在您的Activity中实现IActivityTemplateFactory,将Text设置为新的InArgument<string>,重新创建您的工作流程(将其从工具箱拖到设计图面上!)看看是否能解决您的问题。如果是这样,请告诉我,我会将其转换为带有附加详细信息的答案。 -
如果您想了解更多关于 IATF 的信息,check out my answers regarding how it works and how its used。
-
Text在设计时不会为空。如果你正确绑定它,从你在ExpressionTextBox上写东西的那一刻起,它就不会为空。否则,例如,您将无法对CacheMetadata进行验证。
标签: c# wpf workflow-foundation-4