【发布时间】:2009-09-16 08:47:41
【问题描述】:
我一直在查看 PRISM 2 示例,以了解如何最好地处理我正在开发的新应用程序,这将是一个 PRISM 2/WPF 应用程序。特别看一下 PRISM 附带的 View Injection 示例应用程序,我注意到所有视图都实现了一个接口,该接口允许演示者(或 ViewModel)与视图交互。
过去我是用相反的方式做的,我将presenter注入到视图中,这样视图就可以直接调用presenter上的方法,有点像这样:
public partial class SomeView : ModuleBase
{
private ISomePresenter _somePresenter;
public SomeView (ISomePresenter somePresenter):this()
{
// Give the view a reference to the presenter
_somePresenter = somePresenter;
// Bind the View to the presenter
DataContext = _somePresenter;
}
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
// The view can call actions directly on the presenter (OK I should probably use a command for this)
_somePresenter.SomeAction();
}
}
上面的技术对我来说似乎足够合理,但看看样本我开始质疑这种方法。是否有人对解决此问题的最佳方式有看法(没有双关语)?
- 将演示者添加到视图并让视图与演示者交互
- 将视图添加到演示者并让演示者与视图交互
- 我还没有想到的完全不同的东西?
【问题讨论】: