state handling in windows 8 using mvvmlight

点点圈 提交于 2019-12-22 12:38:09

问题


Implementation of state handling in windows 8 using mvvmlight Is there any method avilable in mvvmligt to manage states in WinRT? How I can duplicate the functionality of default Suspensionmanager by using WinRT? And the second one is about managing navigation cycle ie if I navigated from page A - > B. and the go for suspend and shutdown state. When I re start the application in need to open page B. and while presses back key I need to load A. How I can effectively implement this using MVVM light in my WinRT application?


回答1:


I wrote this originally for WP7 and have been updating for Win8 RT. It allows you to attach attributes to properties you want to keep in your view models, then the PersistenceManager dehydrates them (serialized to file) when the app is suspended and rehydrates when it resumes.

There are examples for WP7 and Win8, basic MVVM pattern and MVVM Light

Obelisk




回答2:


These aren't really MVVM Light functionality. You'll need to do these yourself.

One option would be to create your own navigation service (see example here). The navigation service could use the suspension manager to build/manage a breadcrumb trail for the application. If you added an additional method:

public void GoToMostRecentPage()
{//blah}

You'd be able to call this method in the app start-up and take the user to the appropriate page.

I'd stick with the SuspensionManager. If you want to make it more MVVM friendly you can wrap it in a service that is injected into your viewmodels as required.




回答3:


You might be interested in the open-source Okra App Framework that you can get from NuGet or the CodePlex site I linked to above. It is designed from the ground up to work great with Windows 8 and the MVVM pattern (and you can still use your MVVM Light base classes).

It has a navigation manager that automatically handles everything you mentioned above - managing the application's navigation stack, persistence of the stack on application suspension/termination and even allows view models to persist their own state via a simple interface (like how the SuspensionManager works for pages).

(disclaimer: I am the lead developer on this project)



来源:https://stackoverflow.com/questions/11811138/state-handling-in-windows-8-using-mvvmlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!