StockTrader RI>控制器,演示者,WTF? [英] StockTrader RI > Controllers, Presenters, WTF?

查看:173
本文介绍了StockTrader RI>控制器,演示者,WTF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何通过Prism(复合WPF)项目高级使用WPF。



我观看许多视频和示例,演示应用程序StockTraderRI我问这个问题:



以下每个部分的确切作用是什么?



    $ b $这个东西可以管理数据
  • SomethingView:好的,这是什么显示

  • SomethingPresentationModel:Ok,数据和命令视图绑定到(相当于一个ViewModel)。

  • SomethingPresenter:我不太明白它的用法

  • SomethingController:不明白



我看到一个演示者和一个控制器是不必要的,但我想了解他们为什么在这里。 使用它们时,有人可以告诉我他们的角色吗?

解决方案

>当我第一次通过Prism时,我有完全相同的问题



控制器基本上是跨越整个模块的逻辑,而演示者是针对查看的逻辑。



例如,$ code> Presenter 将响应导致视图中的按钮被禁用的命令。 控制器将响应导致 View (和 Presenter )被完全更改,或者可能在模块的外壳的不同区域加载不同的View / Presenter。



编辑:至于何时使用它们,如果您不需要上述的编排,则可以完全跳过 Controller 。最简单的应用程序将只有一个:




  • 模块:注册视图/演示者进入区域

  • 演示者:响应视图中的命令并修改 ViewModel

  • ViewModel 演示者查看实现 INotifyPropertyChanged

  • 查看:绑定到 ViewModel 并显示UI



编辑:至于Presenter vs ViewModel,您的大多数逻辑应该在您的Presenter中。想想你的ViewModel是为您的观点提供的逻辑,但是Presenter会处理与视图进行交互的后果。



例如,用户点击搜索按钮查看。这将触发 ICommand ,它由您的 Presenter 处理。 Presenter 开始搜索,并设置 ViewModel.IsSearching 属性,该属性将触发PropertyChanged通知它搜索 CanSearch 是基于其他几个属性(例如, IsSearchEnabled&!IsSearching )的只读属性。 View 中的搜索按钮的启用属性绑定到 CanSearch


I am currently learning how to make advanced usage of WPF via the Prism (Composite WPF) project.

I watch many videos and examples and the demo application StockTraderRI makes me ask this question:

What is the exact role of each of the following part?

  • SomethingService: Ok, this is something to manage data
  • SomethingView: Ok, this is what's displayed
  • SomethingPresentationModel: Ok, this contains data and commands for the view to bind to (equivalent to a ViewModel).
  • SomethingPresenter: I don't really understand it's usage
  • SomethingController: Don't understand too

I saw that a Presenter and a Controller are not necessary but I would like to understand why they are here. Can someone tell me their role and when to use them?

解决方案

I had exactly the same problem when I first went through Prism.

Controllers are basically for logic that spans an entire module, whereas Presenters are for logic that is specific to a View.

For example, a Presenter would respond to a command that results in a button in the view being disabled. A Controller would respond to a command that results in the View (and Presenter) being changed entirely, or perhaps loading a different View/Presenter in a different region in the module's shell.

Edit: As for when to use them, you can skip the Controller entirely if you have no need for the orchestration mentioned above. The simplest application will just have a:

  • Module: registers the view/presenter into the Region
  • Presenter: responds to commands from the view and modifies the ViewModel.
  • ViewModel: adapter between Presenter and View that implements INotifyPropertyChanged
  • View: binds to ViewModel and displays UI

Edit: As for Presenter vs ViewModel, most of your logic should be in your Presenter. Think of your ViewModel as housing the logic for your view, but the Presenter as dealing with the consequences of interacting with the view.

For example, the user clicks the "Search" button in your View. This triggers an ICommand, which is handled by your Presenter. The Presenter begins the search and sets the ViewModel.IsSearching property, which fires the PropertyChanged notification for CanSearch. CanSearch is a readonly property that is based on several other properties (eg. IsSearchEnabled && !IsSearching). The "Search" button in the View has its Enabled property bound to CanSearch.

这篇关于StockTrader RI>控制器,演示者,WTF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆