- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我主要具有 ASP.Net 背景,并具有一些 MVC 知识。我也做了一些 Silverlight 和 MVVM,但是我现在即将转向 Winforms,我对它的经验很少,所以我想知道如何处理 MVP。
典型的 MVP 示例显示演示者设置 View 属性(通过某种 IView 接口(interface)),例如具体 View 将该属性值放入文本框中。可以在 MVP 中使用 INotifyPropertyChanged 来代替这种过时的方法吗?如果可以的话,如何使用?一个非常简单的例子将非常有用!
如果我要创建一个实现 INotifyPropertyChanged 的模型,那么这不是更像 MVVM 吗? (即演示者更新模型,并通过 INotifyPropertyChanged 的魔力更新 View )。然而,我在任何地方读到有关 MVVM 和 Winforms 的内容,人们都说它不合适。为什么?我的理解是,您可以对任何控件的属性进行数据绑定(bind),那么 Winforms 缺少什么?我试图了解与 WPF 相比 Winforms 中的数据绑定(bind)的缺点,以及为什么不能使用 MVVM,因为它似乎比 MVP 更容易实现。
提前致谢安迪。
最佳答案
我刚刚检查了 WinForms 中的数据绑定(bind)如何使用 INotifyPropertyChanged。如果 BindingSource 的 DataSource 对象或模型属性对应于DataMember 实现了这一点。您可以在这里充分利用 M. Fowlers 监督演示者/控制者:您甚至不需要手写代码,BindingSource 会在两个方向(模型 -> View 和 View -> 模型)同步 View 与模型属性,并且如果模型支持INotifyPropertyChanged 然后 View 将自动更新。到目前为止我使用过的代码结构:
在 View 初始化期间:
this.bindingSource.DataSource = this.presenter;
设计者生成的代码:
this.textBoxPhone.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource, "Model.Phone", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
模型类:
public class Customer : INotifyPropertyChanged
{
private string _firstName;
public string FirstName
{
get { return _firstName; }
set
{
if (_firstName == value)
return;
_firstName = value;
NotifyPropertyChanged("FirstName");
}
}
private string _lastName;
public string LastName
{
get { return _lastName; }
set
{
if (_lastName == value)
return;
_lastName = value;
NotifyPropertyChanged("LastName");
}
}
private string _company;
public string Company
{
get { return _company; }
set
{
if (_company == value)
return;
_company = value;
NotifyPropertyChanged("Company");
}
}
private string _phone;
public string Phone
{
get { return _phone; }
set
{
if (_phone == value)
return;
_phone = value;
NotifyPropertyChanged("Phone");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
演示者类:
public class CustomerPresenter
{
public CustomerPresenter(Customer model)
{
if (model == null)
throw new ArgumentNullException("model");
this.Model = model;
}
public Customer Model { get; set; }
public ICustomerView View { private get; set; }
}
关于winforms - Winforms MVP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301848/
我相信 Presenter 是负责处理 MVP 应用程序导航方面的人。这是真的还是有异常(exception)? 最佳答案 我认为 View 是唯一负责屏幕导航的 View 。 Here我们对这个“A
我看到了两种实现“加载”反馈的基本方法(例如旋转加载图标): 在演示者中: void displayData() { display.startShowingLoadingIcon();
我有一个方法,用户可以搜索文章编号,如果它在数据库中可用,则文章编号绑定(bind)到 BindingList。现在我想让用户知道该文章是否在数据库中不可用。我该如何以正确的方式做到这一点? 只需将消
我们正在使用 gwt-presenter,但并不是一个特定于此的问题...... 我有一张包含用户的表格。当我在 View 中构建表格时(根据演示者提供的数据),我需要在行的末尾添加两个操作按钮(“编
请用一个简单的例子来描述MVP-Passive View和MVP-Supervising controller的区别。最好显示如何使用 mvp 技术(被动 View 和监督 Controller )绑
GWT 2.1 包含一个 MVP framework其中包括 Google 的 Ray Ryan 在 Google I/O 2009 上概述的 PlaceService 实现。 那个talk启发了一些
在Model-View-Presenter模式中,我们应该在哪里编写用户输入的验证。 最佳答案 Realm 特定的规则/验证应在模型中。您可以使用model.validate()来告知您是否违反规则。
当我们在面试的时候被问到谈谈你对MVC,MVP,MVVM的理解。我们该如何回答,下面我们将对这些模式进行总结。 一、web1.0时代 在web1.0时代,当时并没有前端这个概念,当时如果要开发一个项目
我正在寻找有关 GWT 架构的指南 - 何时使用自包含小部件与 MVP/事件/场所。 背景 阅读了 Google 文档并搜索了 Stackoverflow,gwt-examples 项目为这个问题提供
在地点更改时更新事件状态的最佳做法是什么?假设您有一个带有 View 的事件,该 View 显示类别列表和类别中的项目列表。如果选择了不同的类别,则应用程序会使用类别 ID 转到新位置。然后我只想刷新
在 GWT 中使用 MVP 时,您将如何使用表?例如,如果您有一个用户表,您的 View 看起来像这样吗? public interface MyDisplay{ HasValue users();
我有一个 GWT 应用程序,我正在将 GWT MVP 与地点/事件一起使用。 我的应用程序布局类似于 菜单 |内容 菜单和内容显示将动态变化,其中一个单独变化。我的意思是,当内容显示更改时,我不想更新
我正在使用 Windows 窗体实现 MVP 模式,我对当前的实现有疑问,因为我正试图将其融入更复杂的架构中。 现在我有一个带有属性的完全不可知的 View ,一个在构造函数中注入(inject) V
对所有 GWT 大师的问题。 我是 GWT 的新手,正在尝试了解编写 GWT 应用程序的最佳实践。我经历过"Large scale application development and MVP"基于
我最近一直试图从架构的角度来理解 MVP 架构中交互器和用例之间的关系。我的疑问是关于部件之间的通信以及符合 MVP 标准的内容。 问题是我见过很多相互矛盾的流程图。其中一些似乎每个演示者都有一个交互
我有一个具有 MVP 架构模式的应用程序。 现在,我正在尝试在我的应用程序中实现 Livedata。 我搜索了很多,但我找不到任何教程或示例。 所有教程都说实时数据适用于 MVVM 模式。 在 MVP
我有一个关于在使用 MVP 时如何处理演示者之间的通信的问题。假设我有两个 MVP-triads。一个是产品列表(Triad A),另一个是有关当前所选产品的一般信息(Triad B)。 我如何告诉
我主要具有 ASP.Net 背景,并具有一些 MVC 知识。我也做了一些 Silverlight 和 MVVM,但是我现在即将转向 Winforms,我对它的经验很少,所以我想知道如何处理 MVP。
我读了鲍勃叔叔的《整洁架构书》。我尝试实现简单的例子。我有这个图: 我不明白如何实现红线部分。例如,我有一个简单的网页: 我有 2 个按钮、一个已编辑的文本和一个标签。如果我按下发送到服务器按钮 -
我正在查看 MVP 的 google 示例,我看到 this作为 Activity 的 onCreate 中的最后一个语句: new TaskDetailPresenter(
我是一名优秀的程序员,十分优秀!