Upgrading an existing Windows Phone 7 Application

The following steps are to guide you through the process of upgrading existing App, PhoneApplicationPage and UserControl classes to MVP Controls. There are pre-upgraded samples for each of the template Application Types for Windows Phone 7 included at http://xamlmvp.codeplex.com/releases

Before you begin
  1. Reference the XamlMvp.dll

Upgrading existing Apps

Whilst in XAML (App.xaml)
  1. Include the following namespace into your XAML declaration: xmlns:mvp="clr-namespace:XamlMvp.Controls;assembly=XamlMvp"
  2. Change the root element from Application to mvp:MvpApplication
  3. Remove the shell:PhoneApplicationService definition from the Application.ApplicationLifetimeObjects (we manage this for you)

Whilst in code-behind (App.xaml.cs)
  1. Change your inherited type from Application to XamlMvp.Controls.MvpApplication
  2. Remove all non-user code from the class except for InitializeComponent() in the class constructor
  3. Turn off default mapping conventions by overriding the AddUriMappings method and do not include the call to base. see Default URI mapping conventions

F5 to build and run the application. Your application should still function as it previously did.

Upgrading existing PhoneApplicationPages

Whilst in XAML
  1. Include the following namespace into your XAML declaration: xmlns:mvp="clr-namespace:XamlMvp.Controls;assembly=XamlMvp"
  2. Change the root element from phone:PhoneApplicationPage to mvp:MvpPage

Whilst in code-behind
  1. Change your inherited type from PhoneApplicationPage to XamlMvp.Controls.MvpPage
  2. Implement one of the following interfaces: IMvpPage or IMvpPage<TViewModel> for data bound view pages
    • Alternative create your own interface based on the above to include additional functionality onto your view
    • If you are implementing the data bound version wrap the DataContext property cast to your desired ViewModel type

F5 to build and run the application. Your application should still function as it previously did.

Upgrading existing UserControls

Whilst in XAML
  1. Include the following namespace into your XAML declaration: xmlns:mvp="clr-namespace:XamlMvp.Controls;assembly=XamlMvp"
  2. Change the root element from UserControl to mvp:MvpControl

Whilst in code-behind
  1. Change your inherited type from UserControl to XamlMvp.Controls.MvpControl
  2. Implement one of the following interfaces: IMvpControl or IMvpControl<TViewModel> for data bound view controls
    • Alternative create your own interface based on the above to include additional functionality onto your view
    • If you are implementing the data bound version wrap the DataContext property cast to your desired ViewModel type. There is no set implementation for User Controls.

F5 to build and run the application. Your application should still function as it previously did.

Thats it you are now ready to start creating Presenters and View Models

Last edited Jan 22, 2011 at 6:29 AM by hoffmanic, version 1

Comments

No comments yet.