[英]How to pass ViewModel to CodeActivity using WF4 with MVVM and WPF
I am trying to integrate my current WPF/MVVM application to Workflow Foundation 4.0. 我正在尝试将当前的WPF / MVVM应用程序集成到Workflow Foundation 4.0。
Currently one of my ViewModel methods is invoking my sample CodeActivity sending it some parameters. 目前,我的ViewModel方法之一是调用我的示例CodeActivity向其发送一些参数。
Inside of my CodeActivity execute method I need to call some methods from the calling ViewModel. 在CodeActivity execute方法的内部,我需要从调用ViewModel的方法中调用某些方法。 I would like to know what the best approach is to do this. 我想知道什么是最好的方法。 So far I have identified three possible ways: 到目前为止,我已经确定了三种可能的方法:
So far I have tested options 2 and 3 and they work well apparently. 到目前为止,我已经测试了选项2和3,它们显然工作良好。
What is the optimal way to do this to avoid any issues like thread synchronization problems or other? 避免出现线程同步问题或其他问题的最佳方法是什么?
Thanks in advance, 提前致谢,
Edit: Just to mention a possible scenario: If user picks value 'X' from a given dropdown list in my View I need to add object childA and childB to an ObservableCollection contained by a ParentObject exposed through a public property in my ViewModel. 编辑:仅提及一种可能的情况:如果用户从视图中的给定下拉列表中选择值“ X”,则需要将对象childA和childB添加到由通过ViewModel中的公共属性公开的ParentObject所包含的ObservableCollection中。 The logic to create the child objects and add them to the parent are in my ViewModel. 创建子对象并将其添加到父对象的逻辑在我的ViewModel中。 But I want Workflow to contain the Business Rule itself. 但是我希望工作流包含业务规则本身。
Why does your CodeActivity
need to know anything about a specific view model? 为什么您的CodeActivity
需要了解有关特定视图模型的任何信息? I would look for another solution that allows your activity to maintain as much independence as possible. 我会寻找另一种解决方案,以使您的活动尽可能保持独立性。 Two options I can think of off the top of my head: 我可以想到两个选择:
InArgument<IViewModel>
使用抽象类或接口,以便您的活动不会绑定到单个视图模型,即InArgument<IViewModel>
Without knowing the specifics of your application, I don't know which option would work best (or work at all), but I would avoid a direct connection between a given view model and a given CodeActivity
. 在不了解您的应用程序细节的情况下,我不知道哪个选项最有效(或根本不起作用),但是我会避免在给定的视图模型和给定的CodeActivity
之间建立直接连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.