2011-12-02 10 views
1

我正在嘗試爲Windows Workflow編寫一個自定義活動設計器,該設計器允許用戶在設計窗口中綁定活動參數(與使用Visual Studio屬性對話框相反)。通常情況下,我只寫了這樣的事:是否可以在工作流活動設計器中將數組類型指定爲ExpressionTextBox的ExpressionType?如果是這樣,怎麼樣?

<sapv:ExpressionTextBox Grid.Row="0" Grid.Column="1" OwnerActivity="{Binding Path=ModelItem}" Expression="{Binding Path=ModelItem.Strings, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}" ExpressionType="??s:String[]??" HintText="The strings to combine." /> 

在這種情況下的問題(如可以在上面看到)的是,我不知道ExpressionType應該是什麼數組類型。假設命名空間規範爲xmlns:s="clr-namespace:System;assembly=mscorlib",對於字符串,它將是s:String。是否有可能爲字符串數組做同樣的事情?如果是這樣,請好嗎?

回答

2

您是否嘗試過使用設計器來指定數組類型,然後檢查生成的XML?

+0

這是一個好主意 - 我承認我不太清楚如何使用設計器來指定數組類型,但它只是給我一個框來鍵入ExpressionType,而我不知道該如何放置那裏...) –

0

設計者不允許您以已知/發佈的格式指定數組類型。我一直在試圖弄清楚如何爲通用List類型做同樣的事情,並最終捕獲「Loaded」事件並在後面的代碼中設置ExpressionType。

XAML:

<sapv:ExpressionTextBox 
    Expression="{Binding Path=ModelItem.MyBindingPropertyName,Mode=TwoWay,Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=Out }" 
    OwnerActivity="{Binding Path=ModelItem}" 
    UseLocationExpression="True" 
    Loaded="ExpressionTextBox_Loaded"> 

而在代碼隱藏Loaded事件處理程序:

private void ExpressionTextBox_Loaded(object sender, RoutedEventArgs e) 
{ 
    ((System.Activities.Presentation.View.ExpressionTextBox)sender).ExpressionType = typeof(List<MyType>); 
} 
0

陷入今天這個,我有一個解決方案。我知道它是誰問它擺在首位,但也許有一些人在那裏遇到這樣的情景的傢伙後期:

所以,這是設計師:

<sap:ActivityDesigner x:Class="ARIASquibLibrary.Design.TestArrayActivityDesigner" 
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:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation" 
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation" Collapsible="False"> 
<sap:ActivityDesigner.Resources> 
    <ResourceDictionary> 
     <sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" /> 
    </ResourceDictionary> 
</sap:ActivityDesigner.Resources> 
<Grid> 
    <sapv:ExpressionTextBox 
      MaxWidth="150" 
      MinWidth="150" 
      Margin="5" 
      OwnerActivity="{Binding Path=ModelItem}" 
      Expression="{Binding Path=ModelItem.StringsList, Mode=TwoWay, 
      Converter={StaticResource ArgumentToExpressionConverter}, 
      ConverterParameter=In }"/> 
</Grid> 

創建像這樣的變量部分字符串列表:

enter image description here

將它添加到表達式文本框:

enter image description here

而現在這裏是庫中的代碼:

public sealed class TestArrayActivity : CodeActivity<String[]> 
{ 
    // Define an activity input argument of type List<string> 
    public InArgument<List<string>> StringsList { get; set; } 


    protected override string[] Execute(CodeActivityContext context) 
    { 
     context.GetValue(this.StringsList); 
     return new string[2]; 
    } 

    protected override void CacheMetadata(CodeActivityMetadata metadata) 
    { 
     metadata.AddArgument(new RuntimeArgument(
     "StringsList", typeof(List<String>), ArgumentDirection.In)); 
    } 
} 

添加運行參數,並在關注如何訪問內容:

enter image description here

這關於它。我希望它能幫助新來者。

相關問題