This project is read-only.


There are two types of Presenters in XamlMvp they are Presenter and PagePresenter. PagePresenter differs from Presenter as is allows additional methods for DeHydrating ViewModels (see Using Hydrators to survive Tombstones) and also for Navigation support.

Creating Page Presenters

To create a Page Presenter, create a new class and inherit from the following type XamlMvp.PagePresenter<TView> where is a interface derived from IVewPage. The base type expectes a ViewPage to be passed into its constructor, so at the very least add a Constructor to pass a View into the PagePresenter base class. This example creates a data bound Page Presenter called ApplicationSettingsPresenter.

using XamlMvp;

namespace MvpSample.Presenters
    public class EasyPresenter : PagePresenter<IViewPage>
        public EasyPresenter(IViewPage view)
            : base(view)

You can now start to attach to the following events:
  • RoutedEventHandler Loaded from (IView)
  • RoutedEventHandler Unloaded from (IView)
  • EventHandler<MvpNavigationEventArgs> NavigatedFrom from (IViewPage)
  • EventHandler<CancelEventArgs> BackKeyPress from (IViewPage<TViewModel>);
  • EventHandler Saving from (IViewPage<TViewModel>)
  • EventHandler Canceled from (IViewPage<TViewModel>)
  • EventHandler Deleted from (IViewPage<TViewModel>)

Register a PagePresenter declaration

To add a PagePresenter to the Mvp Presenters collection, in your App.xaml.cs override the InitializePresenters method for the MvpApplication type and add the Presenter using the presenters argument RegisterPage method

protected override void InitializePresenters(IPresenterBinder presenters)
    presenters.RegisterPage<IViewPage, EasyPresenter>((view, state) => new EasyPresenter(view));   

Register a Presenter declaration

To add a Presenter to the Mvp Presenters collection, in your App.xaml.cs use the same InitializePresenters method.

protected override void InitializePresenters(IPresenterBinder presenters)
    presenters.RegisterControl<IView, EasyPresenter>((view, state) => new EasyPresenter(view));   

Bind a Presenter or Page Presenter to a View

To Bind a Presenter to a View or ViewPage use the View.Presenter Attached Property like this:

    mvp:View.Presenter="MvpSample.Presenters.EasyPresenter, MvpSample"

Last edited Jan 22, 2011 at 6:02 AM by hoffmanic, version 2


No comments yet.