Tech Off Post

Single Post Permalink

View Thread: So, how are you implementing MDI in WPF?
  • User profile image

    I would take a look at the prism reference implementation by Microsoft.  Our solution was before prism came out, but essentially our architecture is very similar.  We utilize the MVP pattern and have the concept of a view host.  Basically in XAML you can specify where content should go by placing viewhosts.  Presenters can then inject a view into the view host dynamically.  A view host can itself be an items control that can host multiple views.  Also view hosts can be nested so that you can have a distinct presenter driving each particular view.

    When you utilize this type of architecture doing something like you mentioned is trivial.  To open up a view all you do is instantiate a new copy of the presenter and specify the view host it should inject its view into.  This could be a tab itemscontrol.  Or it could be an itemscontrol that uses a custom template to give views a more MDI like feel within the container.

    It is completely customizable.  Views are completely independent of Presenters and vice versa.  The only contract is in the data binding.

    Lastly we have a separate service that takes care of navigation services.  So when the presenter injects its view, it does so through the navigation service.  This service takes care of remember history and so forth so that the user can go back & forth among the views.

    The nice thing about this architecture is that the actual size of the supporting libraries are very minimal and very testable.  This follows good agile principles.