如何在ActivityDesigner中访问活动参数?

时间:2019-05-30 12:57:39

标签: arguments workflow-foundation activitydesigner

我需要在InArgument处获取自定义活动的ActivityDesigner值。

MyActivity:

[Designer(typeof(ReadTextDesigner))]
public sealed class ReadText : CodeActivity
{
    public InArgument<string> ImageName { get; set; }

    protected override void Execute(CodeActivityContext context)
    {
    }
}

我的设计师:

public partial class ReadTextDesigner
{
    public ReadTextDesigner()
    {
        InitializeComponent();
        //this.ModelItem is null here.. WHY is it null?
        //How do I get Activity's ImageName here?
    }
}

我还有一个按钮,如下图所示,当您单击它时,我可以设置这样的自定义活动值:

enter image description here

private void BtnStart_OnClick(object sender, RoutedEventArgs e)
    {
        this.ModelItem?.Properties["ImageName"]?.SetValue(new InArgument<string>()
        {
            Expression = "some value"
        });
    }

XAML:

<sapv:ExpressionTextBox 
    Expression="{Binding Path=ModelItem.ImageName, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In }"
    ExpressionType="s:String"
    HintText="Enter a string"
    OwnerActivity="{Binding Path=ModelItem}"
    Width="110"
    Margin="0,5"
    Grid.Row="0"
    MaxLines="1"
    x:Name="TxtImagePath"/>

<Button Grid.Column="0" Grid.Row="1" Content="Get Image" HorizontalAlignment="Center" Click="BtnStart_OnClick" x:Name="BtnStart"/>

如何获取Activity InArgument ReadTextDesigner构造函数?

1 个答案:

答案 0 :(得分:1)

这很奇怪,但是我找到了解决方法。尽管这是 A 解决方案,但我希望有更好的解决方案;

由于在构造函数中无法获得Dim ws As Worksheet Dim ColumnLetter As Variant Set ws = Sheets("HSR") Worksheets("HSR").Select lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row lr2 = Sheets("Combined").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row ColumnLetter = Split(ws.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0) Range("A2:C" & lr).Copy Sheets("Combined").Range("A" & lr2 + 1) Range("E2:ColumnLetter" & lr).Copy Sheets("Combined").Range("D" & lr2 + 1) End Sub ,因此我在主线程之外创建了一个新的df.loc[df.category.astype('str')=='-','category']=df[df.category.astype('str')=='-']['names'].apply(lib.get_category) 。这个新线程等待2毫秒,然后尝试获取ModelItem并以某种方式成功。

这是新修改的Thread代码(注意:我只更改了ModelItem代码,没有其他内容)

ReadTextDesigner

ReadTextDesigner不再为null,并带有必要的值。 希望这可以帮助某人或某人发布更好的解决方案。

干杯!