MVP and rich user interface

I want to implement an MVP pattern for my application. MVP Passive browsing actually. Therefore, I came to a problem, it was easy, but cannot decide which way I should take, so I want to ask your guru how to work correctly with MVP and display a rich interface.

I mean, let's say we need to display some data, and the client wants it to be a TreeView. There is a requirement: if the user selects another treenode, then the application is updated with new data or something like that. At the moment, I'm not sure how to implement View. (All view logic is passed to the master)

I don’t think it’s a good idea to expose the WinForms class

ISomeForm : IView {
 //Presenter will take control of this TreeView.
 TreeView Host {
  get;
  }
}

or exposing data models

ISomeForm : IView {
 //View knows how to display this data
 List<MyDataNodes> Items {
  get;
  set;
 }
}

or using other View interfaces.

ISomeForm : IView {
 //Presenter knows what Views presenter should display.
 List<IDataView> Items {
  get;
  set;
 }
}

Any suggestions?

+5
3

View.

MVVM WPF, , UI/Logic .

+1

, MVC. TreeView, . TreeView. , , , . , ( ). . :

public class MvcMessage
{
    public object Source { get; private set; }
    public MessageType MessageType { get; private set; }
    public Type EntityType { get; private set; }

    public IList InvolvedItems { get; set; }
    public int NumAffected { get; set; }
    public EventArgs SourceEventArgs { get; internal set; }

    /// <summary>
    /// Name of property who changed its value. Applies to models implementing INotifyPropertyChanged.
    /// </summary>
    public string PropertyName { get; set; }

    public MvcMessage(object source, MessageType messageType, Type entityType)
    {
        this.Source = source;
        this.MessageType = messageType;
        this.EntityType = entityType;
    }

    public void Reroute(Type newEntityType)
    {
        MvcMessage reroutedMessage = (MvcMessage)MemberwiseClone();
        reroutedMessage.EntityType = newEntityType;
        Controller.NotifyAll(reroutedMessage);
    }
}

... MessageType - , .

IView :

public delegate void ViewEventHandler(MvcMessage message);

public interface IView : IViewPage, IWin32Window
{
    event ViewEventHandler ViewEvent;
    ...
}
+1

You should go more along the lines of the last two examples; The view should not show WinForm-ish details to the host. See this answer for details on how to deal with your problem when updating TreeView, especially paragraph 5 .

+1
source

All Articles