是否有Windows Phone的屏幕之间导航的类型安全的方法吗? [英] Is there a typesafe way of navigating between screens in Windows Phone?

查看:106
本文介绍了是否有Windows Phone的屏幕之间导航的类型安全的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式,我的应用程序屏幕之间进行导航。基本上我到目前为止看到包括传递一个字符串URI到的NavigationService,完整的查询字符串参数,例如

I'm looking for a way to navigate between screens in my app. Basically what I've seen so far consists of passing a string URI to the NavigationService, complete with query string parameters., e.g.

NavigationService.Navigate(new Uri("/MainPage.xaml?selectedItem=" +bookName.Id, UriKind.Relative));

我不是这虽然真正热衷最终,因为它需要魔法字符串,它们可以导致在道路上的问题。

I'm not really keen on this though ultimately because it requires magic strings, and they can lead to problems down the road.

在理想情况下我刚刚创造我想要导航到类的一个实例,传递参数作为参数传递给构造函数。这可能吗?如果是这样,怎么样?

Ideally I'd just create an instance of the class I want to navigate to, passing the parameters as arguments to the constructor. Is this possible? If so, how?

推荐答案

虽然实际导航最终还是不得不使用字符串,可以创建或使用的包装是类型安全的。

While the actual navigation will have to use strings eventually, you can create or use a wrapper that is type safe.

我建议在看卡利微即使你只用它的类型安全航行。这里是一个片段<一个href=\"http://wp.qmatteoq.com/first-steps-with-caliburn-micro-in-windows-phone-8-collections-and-navigation/\">from在WP8使用它的教程的:

I would suggest looking at Caliburn Micro even if you only used it for the type safe navigation. Here is a snippet from a tutorial on using it in WP8:

这是自带的工具包中的NavigationService第一个支持的视图模式办法:不是宣称这是我们要采取的用户(即标准方法)页面的URL,我们声明这是我们要显示的视图模型。 该服务将创建正确的URL的关怀和显示与视图模型相关联的视图

The NavigationService that comes with the toolkit supports a view model first approach: instead of declaring which is the URL of the page where we want to take the user (that is the standard approach), we declare which is the ViewModel we want to display. The service will take care of creating the correct URL and display the view that is associated with the view model.

另外,您可以看看的Windows Phone MVC 其中也有一些类型的航行安全。你甚至可能只是能够拉动导航code到你自己的使用,因为它是根据 MS-PL

Alternatively you could look at Windows Phone MVC which also has some type safe navigation. You might even just be able to pull the navigation code out to use on your own since it's licensed under MS-PL.

这篇关于是否有Windows Phone的屏幕之间导航的类型安全的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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