ViewModel中的NavigationService [英] NavigationService in ViewModel
问题描述
你好
那我有什么问题?我使用MVVM开发WP应用程序.问题是,我无法在ViewModel中使用NavigationService.网络上有一些有关此问题的文章.我尝试了这个解决方案 http://geekswithblogs.net/lbugnion/archive/2011/01/06/navigation-in-a-wp7-application-with-mvvm-light.aspx .工作正常但是只有2种方法和1个事件.原始的NavigationService更复杂.你怎么看?我应该创造更多东西吗?
so what's my problem? I develop WP application using MVVM. Problem is, i cannot use NavigationService in ViewModel. Some articles are on web about this problem. I tried this solution http://geekswithblogs.net/lbugnion/archive/2011/01/06/navigation-in-a-wp7-application-with-mvvm-light.aspx . It's working. But only 2 methods and one event. Original NavigationService is more complex. What do you think? Should I create more things?
其他解决方案:我可以使用PhoneApplicationFrame.Navigate导航到上一页,但是它会创建新实例.
Other solution: I could use PhoneApplicationFrame.Navigate to navigate to previous page, but it creates new instance.
推荐答案
I在决定如何构建它方面也很困难.我的ViewModel位于可移植类库(PCL)中,增加了一层分隔,因此Windows Store应用程序也可以使用它们.我认为没有什么比现成的解决方案更容易/更容易了 除了您提供的链接.我可能错过了一些东西,但是听起来您需要在ViewModels中滚动自己的导航管理器.这不是我想冒险的事情,所以我要牺牲我的MVVM模型的纯度来制作单行 导航调用后面的代码.如果您找到更好的方法,请发表!
I'm having a hard time deciding how to build this as well. My ViewModels are in a Portable Class Library (PCL), adding a layer of separation, so they can be used by a Windows Store app as well. I don't think are are any easier\out of the box solutions aside from the link you provided. I might have missed something, but it sounds like you would need to roll your own nav manager in your ViewModels. This isn't something I want to venture into so I'm sacrificing the purity of my MVVM model to make single line navigation calls in the code behind. Please post if you find a better approach!
这篇关于ViewModel中的NavigationService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!