/// <summary>Initializes the view model and registers events so that the OnLoaded and OnUnloaded methods are called. /// This method must be called in the constructor after the <see cref="InitializeComponent"/> method call. </summary> /// <param name="viewModel">The view model. </param> /// <param name="view">The view. </param> public static void RegisterViewModel(ViewModelBase viewModel, FrameworkElement view) { viewModel.Initialize(); view.Loaded += (sender, args) => viewModel.CallOnLoaded(); view.Unloaded += (sender, args) => viewModel.CallOnUnloaded(); }
/// <summary>Binds the <see cref="ViewModelBase.IsLoading"/> property of the view model to /// the progress bar visibility of the status bar (Windows Phone only). </summary> /// <param name="viewModel">The view model. </param> public static void BindViewModelToStatusBarProgress(ViewModelBase viewModel) { var type = Type.GetType( "Windows.UI.ViewManagement.StatusBar, " + "Windows, Version=255.255.255.255, Culture=neutral, " + "PublicKeyToken=null, ContentType=WindowsRuntime"); var method = type.GetTypeInfo().GetDeclaredMethod("GetForCurrentView"); viewModel.PropertyChanged += (sender, args) => { if (args.IsProperty<ViewModelBase>(i => i.IsLoading)) { if (viewModel.IsLoading) { dynamic statusBar = method.Invoke(null, null); statusBar.ProgressIndicator.ShowAsync(); } else { dynamic statusBar = method.Invoke(null, null); statusBar.ProgressIndicator.HideAsync(); } } }; }
/// <summary>Initializes the view model and registers events so that the OnLoaded and OnUnloaded methods are called. /// This method must be called in the constructor after the <see cref="InitializeComponent"/> method call. </summary> /// <param name="viewModel">The view model. </param> /// <param name="view">The view. </param> /// <param name="registerForStateHandling">Registers the view model also for state handling /// The view model has to implement <see cref="IStateHandlingViewModel"/> and the view must be a <see cref="MtPage"/>. </param> public static void RegisterViewModel(ViewModelBase viewModel, FrameworkElement view, bool registerForStateHandling) { viewModel.Initialize(); view.Loaded += (sender, args) => viewModel.CallOnLoaded(); view.Unloaded += (sender, args) => viewModel.CallOnUnloaded(); RegisterViewModelForStateHandling((IStateHandlingViewModel) viewModel, (MtPage) view); }
/// <summary>Initializes the view model and registers events so that the OnLoaded and OnUnloaded methods are called. /// This method must be called in the constructor after the <see cref="InitializeComponent"/> method call. </summary> /// <param name="viewModel">The view model. </param> /// <param name="registerForStateHandling">Registers the view model also for state handling /// The view model has to implement <see cref="IStateHandlingViewModel"/> and the view must be a <see cref="MtPage"/>. </param> public void RegisterViewModel(ViewModelBase viewModel, bool registerForStateHandling = true) { ViewModelHelper.RegisterViewModel(viewModel, this, registerForStateHandling); }
/// <summary>Binds the <see cref="ViewModelBase.IsLoading"/> property of the view model to /// the progress bar visibility of the status bar (Windows Phone only). </summary> /// <param name="viewModel">The view model. </param> public void BindViewModelToStatusBarProgress(ViewModelBase viewModel) { ViewModelHelper.BindViewModelToStatusBarProgress(viewModel); }