How i can implement state handling (running / resume / Terminate states ) using mvvm light. The major issue i a facing is with Navigation. I am totally uncontrolled with the navigation stack. How i can effectively manage this with MVVM Light.
Start a new project using either the GridView or SplitView templates and take a look at SuspensionManager.cs in the Common folder. It has a method called RegisterFrame which, when called, starts tracking all of the navigation events from the frame and attempts to save off and restore state when the application suspends and resumes.
The applications main frame is registered with the SuspensionManager in App.OnLaunched (App.xaml.cs) and Saving is done in App.OnSuspending.
Finally, take a look at LayoutAwarePage.cs, also in the Common folder. You can inherit from LayoutAwarePage to get Portrait and Snapped design time support. It also attempts to handle navigation state caching by leveraging the SuspensionManager. So, no matter whether your page is navigated to from another page or as part of a resume, the virtual method LoadState is called with the correct data.
Obviously this pattern is managing navigation state directly in the page itself, but you could tweak this pattern to create a sort of "SuspensionService" that your ViewModels could leverage in the same way.
You might be interested in the open source Okra App Framework that is freely available on CodePlex and NuGet (disclaimer: I am the lead developer on this project). This has been designed from the ground up for Windows 8 applications, in particular those that use the MVVM pattern (and you can still use the MVVM Light base classes to define your view-models).
Of particular interest it includes,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With