2010-04-26 66 views
1

我正在尝试为我有的活动添加自定义活动设计器。活动看起来有点像:将自定义活动设计器的输出绑定到活动参数

public class WaitForUserInputActvitiy : NativeActivity 
{ 
    public InArgument<UserInteractionProperty[]> UserInteraction { get; set; } 
} 

我试图把设计师的活动,使之更好一点来设置这些值(这样你就不会结束在直接键入VB我的设计师。基于思维空间属性网格,我有我想从这些值,并把它们到InArgument的ObservableDictionary来源。目前我使用

private void TestGrid_LostFocus(object sender, RoutedEventArgs e) 
{ 
    using (ModelEditingScope editingScope = this.ModelItem.BeginEdit()) 
    { 
     Argument myArg = Argument.Create(typeof(WaitForUserInputActvitiy), ArgumentDirection.In); 
     this.ModelItem.Properties["UserInteraction"].SetValue(source.Values.ToArray()); 

     editingScope.Complete(); 
    } 
} 

然而这会导致一个ArgumentException“的类型UserInteractionProperty [对象]无法转换为InArgument`1 [UserInteractionProperty []]。

那么如何将UserInteractionProperties数组转换为InArgument?

回答

1

我有点迟了,在这里有一个答案,我怀疑你已经发现了你的bug,因为当你喜欢编写使用UserInteraction的代码时,你将没有从哪里得到它们。

所以问题是this.ModelItem.Properties["UserInteraction"]正在为InArgument<UserInteractionProperty[]>属性建模,并且您试图使用值为UserInteractionProperty[]的值来设置它。 InArgument<UserInteractionProperty[]>是要使用其他工作流程元素提供UserInteractionProperty列表的类型。看起来情况并非如此 - 我怀疑你想宣布你的财产只是UserInteractionProperty[]

public class WaitForUserInputActvitiy : NativeActivity 
{ 
    public UserInteractionProperty[] UserInteraction { get; set; } 
} 

但是,我会建议宣布它为Collection<UserInteractionProperty>,因为这是更好。