MVVM Light Windows Phone 应用程序中是否有通用的导航约定?
随着我的应用程序变得越来越大,我发现相同类型的实体越来越多地出现在整个应用程序中,通常是在列表框中。
当有人点击实体时,我想导航到该实体的详细视图。
产品就是这样的一个例子:它按类别出现在产品列表中,出现在搜索结果中,或者可能显示为已保存的收藏夹。在我的实例中,所有这些都来自本地 SQLCE 存储中的表。
每次我以某种方式显示实体以便有人可以点击它时,我基本上都会删除相同的代码:订阅列表框中的 SelectionChange 事件,提取实体,使用 MVVM Light 消息传递来表明所选实体已更改,然后调用 NavigationService 来执行其业务。
有没有人做过类似的事情,如果有,你想出了什么?或者更重要的是,如果我忽略了一些 MVVM Light 工具包约定,您能给我指出正确的方向吗?
As my app gets bigger I am finding that the same type of entity is appearing more and more throughout, typically in a listbox.
When someone taps on the entity, I want to navigate to the detailed view of this entity.
An example of this would be a product: it appears in a product list by category, it appears in search results, or it might appear as a saved favourite. In my instance, all of these would come from a table in local SQLCE storage.
Every time I surface the entity in some way that someone could tap on it, I basically cut the same code: subscribe to the SelectionChange event on the listbox, extract the entity, use MVVM Light messaging to signal that the selected entity has changed, then call NavigationService to do its business.
Has anyone worked on something similar and, if so, what have you came up with? Or more importantly, if there's some MVVM Light toolkit convention that I'm overlooking, could you please point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您现在是从代码隐藏还是视图模型调用 NavigationService ?如果是前者,您可以检查 LBugnion 的 WP7 导航文章,用于从 VM 触发它。如果将其与
EventToCommand
行为结合起来 (就像这里)您应该能够在虚拟机中创建一个漂亮且干净的“MyEntitySelected”命令,该命令将实体作为参数。Are you calling the NavigationService from code-behind or the View Model now? If the former, you could check the WP7 Navigation arcticle by LBugnion for triggering it from the VM. If you combine that with the
EventToCommand
behavior (like in here) you should be able to create a nice and clean "MyEntitySelected" command in the VM which takes the entity as a parameter.我认为这里的问题是,如何处理这个问题而不每次都剪切/粘贴相同的代码?如果是这种情况,也许尝试将实体/列表框打包在 XAML 用户控件中!看看这个: http://www .windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps
然后,如果表示需要不同,您可以看看这个:http://www.windowsphonegeek.com/articles/Implementing-Windows -Phone-7-DataTemplateSelector-and-CustomDataTemplateSelector(此示例在一个列表框中执行不同的样式,但您可以将其更改为仅应用不同的样式)每个不同页面上的样式,上面有一个列表框)
I think the question here is, how do I deal with this without cut/paste the same code each time? If this is the case, maybe trying to package the entity/listbox thing in a XAML usercontrol! Take a look at this: http://www.windowsphonegeek.com/articles/Creating-a-WP7-Custom-Control-in-7-Steps
Then if the representation needs to be different, you could have a look at this: http://www.windowsphonegeek.com/articles/Implementing-Windows-Phone-7-DataTemplateSelector-and-CustomDataTemplateSelector ( this example does different styling in one listbox, but you can change this to only apply different style on each different page with a listbox on it )