MVP的WinForms网格活动问题 [英] Winforms MVP Grid Events Problem

查看:162
本文介绍了MVP的WinForms网格活动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现MVP模式的WinForms的。它是一种简单的与一个按钮和一个网格,就按一下按钮,网格将加载,并且用户可以在数值填写到电网。

I am trying to implement the MVP pattern for WINFORMS. Its a simple for with a button and a Grid, on button click, the grid will load, and user can fill in values into the grid.

有关我的按钮单击事件,我有这样的事情:

For my button click event, I have something like this:

_ presenter.LoadGrid();

_presenter.LoadGrid();

这是简单明了。

我的问题是,在关于格... 我打算有一排点击事件触发....启用/禁用后续输入字段的特定列/行格等。

My question is, in regards to grid... I am planning to have a row click event firing....for enabling/disabling the subsequent input fields for the specific columns/rows of the grid etc.

据我所知,presenter不应包含任何GUI元素和View(表格)真的不应该包含逻辑?

I understand that the presenter should not contain any GUI elements and the View(form) shouldn't really contain Logic?

所以,有这种GridRowClick事件触发,我需要根据业务规则(逻辑)操纵网格(GUI)。我让presenter处理的单击事件或形式的逻辑之间失去了什么?

So, to have that GridRowClick event firing, I need to manipulate the grid (GUI) based on business rules (Logic). I am lost between letting the presenter handle the logic of that click event or the form?

如果在presenter是处理单击事件,不会包括GUI组件? 如果视图是处理click事件中,字段名等都是业务驱动的(逻辑),动态绑定根据数据表从业务层返回。

If the presenter is to handle the click event, wont that include the gui components? If the view is to handle the click event, the fieldnames etc are all business driven(logic), dynamically binded based on datatable returned from the business layer.

任何意见将大大AP preciated。

Any advice will be much appreciated.

干杯

推荐答案

有(至少)MVP的两种变体。

There are (at least) two variants of MVP.

  • 在被动视图模式
  • 在监督控制器模式

被动视图,顾名思义,把用户界面为用户和应用程序之间的或多或少的被动接口。它移动尽可能多的可测试code到presenter尽可能让视图来处理只是最基本的用户界面的更新。

Passive View, as its name suggests, treats the UI as a more or less passive interface between the user and the application. It moves as much testable code to the presenter as possible leaving the view to handle only the most basic UI updates.

监督管理者,认为通过让其处理数据的同步多一点责任。这通常是通过数据进行绑定。

Supervising controller gives the view a little more responsibility by letting it handle data synchronization. This is usually done through data binding.

在这两种情况下事件处理被委托给presenter方式完成的:

In either case event handling is accomplished by delegating to a presenter method:

EventHandler()
{
    presenter.HandleEvent();
}

如果处理事件需要做出改变的形式,你暴露什么需要更新的属性:

If handling the event requires making changes to the form, you expose what needs to be updated as a property:

public string PropertyThatNeedsToBeUpdated
{
    get
    {
        return Control.Property;
    }
    set
    {
        Control.Property = value;
    }
}

有关被动视图,网格是一道坎。其复杂性使得繁琐的捕捉到所有可能发生的事件。通过监督控制器,网格是比较容易,因为你离开数据同步至绑定控件中的数据。

For Passive View, grids are a hurdle. Their complexity make it cumbersome to capture all the possible events. With Supervising controller, grids are much easier since you leave data synchronization up to the data bound controls.

您必须使主观判断哪个更适合您的情况。

You have to make the judgment call as to which is more appropriate for your situation.

这篇关于MVP的WinForms网格活动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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