2013-02-01 65 views
5

我在使用Workflow Foundation中的自定義活動和設計器時遇到問題。對於這個問題的緣故,我創建了一個非常簡單的活動,如下圖所示: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> 

當我在文本框中鍵入的東西,我得到一個錯誤:無效的l值表達式,但如果我在屬性網格上鍵入值,則更新文本框。

有沒有人見過這個?

謝謝。從你的XAML

+0

你確定你的SSCCE是正確的?就目前而言,在設計時,'Text'將會是* null *,這可能會首先引起'ArgumentToExpressionConverter'問題。嘗試在你的Activity中實現'IActivityTemplateFactory',將'Text'設置爲一個新的'InArgument ',重新創建你的工作流程(將它從工具箱拖到設計表面上!),看看是否解決了你的問題。如果是這樣,讓我知道,我將它轉換爲一個答案與addl的細節。 – Will

+0

如果你想了解更多關於IATF的信息,[查看我的回答,瞭解它如何工作以及如何使用](http://stackoverflow.com/search?q=user%3A1228+is%3Aanswer+IActivityTemplateFactory)。 – Will

+0

'文字'在設計時不會爲空。如果你正確地綁定它,那麼當你在'ExpressionTextBox'上寫東西的時候它不會是空的。否則,例如,您將無法對'CacheMetadata'進行驗證。 – Joao

回答

4

刪除UseLocationExpression財產或把它轉化爲。其餘的代碼看起來是正確的。

檢查MSDN屬性備註:

A location expression (or L-value expression) is a type of expression that evaluates to an identifier and can be placed on the left hand side of an assignment statement. When you are binding the ExpressionTextBox to an Out argument, you would set this property to True.

只有當你要綁定的OutArgument使用。

+0

謝謝Jota,它像一個魅力! –

相關問題