-
Notifications
You must be signed in to change notification settings - Fork 76
ViewModelHelper
Rico Suter edited this page Jul 8, 2015
·
4 revisions
- Package: MyToolkit.Extended
- Platforms: WinRT, UWP
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.
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);
}
}