WinRT 在页面之间传递 ViewModel [英] WinRT Passing ViewModel between pages

查看:33
本文介绍了WinRT 在页面之间传递 ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个两页的 Windows 8 应用程序.一个查看页面和一个设置页面.两个页面使用相同的视图模型.我可以在页面之间传递视图模型来使用它,但是我无法保存状态,因为我在页面之间传递了一个复杂的类型(这与它们如何保持引用有关,并阻止您保存).

I have a two page Windows 8 application. A view page and a settings page. Both pages use the same view model. I can pass the view model between pages to work with it, but then I can not save state because I have passed a complex type between pages (it has to do with how they keep references, and stops you from saving).

所以我想我需要在每个页面上保存并重新加载我的视图模型?我找不到关于什么是最佳做法的好的参考资料.

So I guess I need to save and reload my view model on each page? I can't find a good reference on what is a best practice for this.

推荐答案

通常 WinRT 会在 App.cs 中初始化的 Root 框架中导航.最好在 MainPage 中定义一个 Frame 对象并在此框架内导航所有页面.您的框架数据上下文可以绑定到 ViewModel.

Usually WinRT navigates through Root frame, which initialized in App.cs. It is better to define a Frame object in MainPage and navigate all your pages within this frame. Your frame datacontext can bind to ViewModel.

这篇关于WinRT 在页面之间传递 ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆