我在使用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
你確定你的SSCCE是正確的?就目前而言,在設計時,'Text'將會是* null *,這可能會首先引起'ArgumentToExpressionConverter'問題。嘗試在你的Activity中實現'IActivityTemplateFactory',將'Text'設置爲一個新的'InArgument',重新創建你的工作流程(將它從工具箱拖到設計表面上!),看看是否解決了你的問題。如果是這樣,讓我知道,我將它轉換爲一個答案與addl的細節。 –
Will
如果你想了解更多關於IATF的信息,[查看我的回答,瞭解它如何工作以及如何使用](http://stackoverflow.com/search?q=user%3A1228+is%3Aanswer+IActivityTemplateFactory)。 – Will
'文字'在設計時不會爲空。如果你正確地綁定它,那麼當你在'ExpressionTextBox'上寫東西的時候它不會是空的。否則,例如,您將無法對'CacheMetadata'進行驗證。 – Joao