The page has been moved to GitHub

ViewModelHelper

Package: MyToolkit.Extended
Platforms: WinRT(Universal)

Provides static methods for connecting a view model to a view.

Static methods:
  • RegisterViewModel: Registers the view model life cycle events and calls the initialize method. See ViewModelBase for more information.
  • BindViewModelToStatusBarProgress: Binds the ViewModelBase's IsLoading property to the Windows Phone system tray ProgressIndicator.

Usage

The static methods should be called in the view's constructor:

public sealed partial class MyPage
{
    public MyPageModel Model { get { return (MyPageModel)Resources["ViewModel"]; } }

    public MainPage()
    {
        InitializeComponent();
        ViewModelHelper.RegisterViewModel(Model, this); 
        ViewModelHelper.BindViewModelToStatusBarProgress(Model); 
    }
}

The class MtPage directly provides the RegisterViewModel and BindViewModelToStatusBarProgress methods which internally call the ViewModelHelper methods:

public sealed partial class MyPage
{
    public MyPageModel Model { get { return (MyPageModel)Resources["ViewModel"]; } }

    public MainPage()
    {
        InitializeComponent();
        RegisterViewModel(Model); 
        BindViewModelToStatusBarProgress(Model);
    }
}

Last edited Jun 3, 2015 at 10:52 PM by rsuter, version 12