C# 工作流基础-在自定义设计器中分配参数 我在工作流基础中使用自定义活动和设计器遇到了问题。为了回答这个问题,我创建了一个非常简单的活动,如下所示: [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); } } [Designer(typeof(TesteDesigner))] 公共密封类Teste:CodeActivity { //定义字符串类型的活动输入参数 [必需参数] 公共非语法文本{get;set;} //如果活动返回值,则从CodeActivity派生 //并从Execute方法返回值。 受保护的覆盖无效执行(CodeActivityContext上下文) { //获取文本输入参数的运行时值 string text=context.GetValue(this.text); } }
设计师如下:C# 工作流基础-在自定义设计器中分配参数 我在工作流基础中使用自定义活动和设计器遇到了问题。为了回答这个问题,我创建了一个非常简单的活动,如下所示: [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); } } [Designer(typeof(TesteDesigner))] 公共密封类Teste:CodeActivity { //定义字符串类型的活动输入参数 [必需参数] 公共非语法文本{get;set;} //如果活动返回值,则从CodeActivity派生 //并从Execute方法返回值。 受保护的覆盖无效执行(CodeActivityContext上下文) { //获取文本输入参数的运行时值 string text=context.GetValue(this.text); } },c#,wpf,workflow-foundation-4,C#,Wpf,Workflow Foundation 4,设计师如下: <sap:ActivityDesigner x:Class="ActivityDesignerLibrary1.TesteDesigner" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<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>
当我在文本框中键入内容时,会出现一个错误:l值表达式无效,但如果我在属性网格中键入值,文本框将更新
有人见过这个吗
谢谢。从XAML中删除UseLocationExpression属性或将其设置为False。代码的其余部分似乎是正确的
查看以下内容的属性备注:
位置表达式(或L值表达式)是表达式的一种类型
它的计算结果是一个标识符,可以放在左手边
赋值语句的边。当您绑定
ExpressionTextBox设置为Out参数时,可以将此属性设置为
对
仅当您想绑定OutArgument时才使用它。您确定您的SSCE正确吗?目前,在设计时,
文本
将为空,这可能会导致在第一次使用时,参数expressionconverter
出现问题。尝试在您的活动中实现IActivityTemplateFactory
,将文本设置为等于新的inagrament
,重新创建您的工作流(将其从工具箱拖到设计图面上!),然后查看这是否解决了您的问题。如果是这样,请告诉我,我会将此转换为包含addl详细信息的答案。如果您需要有关IATF的更多信息,.Text
在设计时不会为空。如果您正确绑定了它,那么从您在ExpressionTextBox
上编写内容时,它就不会为空。例如,否则您将无法对CacheMetadata
进行验证。