如何获取 ActivityContext 以便获取 InArgument 的值
我目前正在研究 Workflow Foundation。我有一个包含参数的活动:
System.Activities.InArgument<double> Temperature
但是,我想在我的活动中获取此参数的值,以便对其进行一些验证(并根据此参数在我的活动中设置属性)。我知道有一个 Get 方法需要 ActivityContext ,因此实际值将在运行时得知。我的问题是,如何获取 ActivityContext,或者有更好的方法吗?
注意:我在我的应用程序中托管 WorkflowDesigner,我将其删除上的活动。因此,Activity1 包含一个属性“Temperature”,并且该属性作为 InArgument 传递到 Activity2 中。然后我验证 Activity2,但到目前为止无法获取 ActivityContext。我在执行时不需要它,但在设计时需要它。
提前致谢。
I'm currently tinkering around with Workflow Foundation. I have an activity which contains the argument:
System.Activities.InArgument<double> Temperature
However, I want to get the value of this argument in my activity in order to do some validation with it (and also set properties in my activity based on this argument). I understand there is a Get method which takes an ActivityContext, so the actual value would be known at runtime. My question is, how can I get the ActivityContext, or is there a better way?
Note: I'm hosting the WorkflowDesigner in my app which I drop my activities on. So Activity1 contains a property "Temperature", and this is passed into Activity2 as an InArgument. I then validate Activity2, but so far can't get the ActivityContext. I don't need it at execution time, but at design time.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想要使用依赖属性,就像在 WF3 中那样,在设计时将 Activity1 的输出与 Activity2 的输入联系起来。。这是正确的吗?
在 WF4 重写中,他们删除了所有允许这样做的依赖属性内容。
特别谈到在设计时访问 ActivityContext 项:我认为这是不可能的。 AC 对象是在活动执行时创建的。它允许一个活动的一个实例被执行多次(循环的每次迭代都有一个与其关联的单独的 AC 对象,因为 AC 对象是在运行时创建的)。
这里是一篇很好的 Microsoft 博客文章,描述了 WF3 和 WF4 活动运行时执行之间的差异。我认为这可能有助于澄清您想要做什么以及如何解决问题。
It sounds like you are wanting to use dependency properties like they had in WF3 to tie the output of activity1 to the input of activity2 at design time. Is that correct?
In the WF4 re-write they ripped out all of the dependency property stuff that allowed this.
Speaking specifically to getting access to the ActivityContext item at design time: I don't believe that is going to be possible. The AC object is created at the time of activity execution. It is what allows one instance of an activity to be executed multiple times (each iteration of a loop has a separate AC object associated with it because the AC object is created during runtime).
Here is a good Microsoft blog article describing the difference between WF3 and WF4 activity run-time execution. I think it might help clarify what you are wanting to do and how to approach the problem.
您可以传递
ActivityContext< /code> 将 Activity2 作为参数
?
使用自定义活动设计器怎么样?
Can you pass the
ActivityContext
to Activity2 as an argument?What about using Custom Activity Designers?