Windows Phone 7 中 ViewModel 之间的通信

发布于 2024-10-08 00:41:34 字数 370 浏览 0 评论 0原文

我们将 Caliburn.Micro 用于一个简单的 Windows Phone 7 应用程序,该应用程序拍摄特定库存商品的照片,然后保存图像和包含用户输入信息的 xml 文件。

我有第一个屏幕,其中有单击按钮,“CameraCaptureTask”获取照片,我读取照片并将其保存到存储中,但现在我不确定如何将用户带到另一个视图并传递文件名和第一个视图中生成的唯一 ID。

我尝试使用 NavigationService.Navigate("...") 使用查询字符串,但无法在 ViewModel 中获取查询字符串。

我很困惑,比如说当你制作向导时,如何从一个视图传递到另一个视图 - 不使用单例或黑客方式。有没有一个好的 Caliburn.Micro 方法和一个很好的例子?

We are using Caliburn.Micro for a simple Windows Phone 7 Application that takes a photo of a particular stock item, and then saves the image and a xml file with information user enters.

I have first screen with button to click and "CameraCaptureTask" gets photo, I read photo and save to storage but now I'm not sure how to take user to another View and pass the filename and a unique ID generated in the first View.

I tried NavigationService.Navigate("...") with a query string but I cannot get Querystring in ViewModel.

I'm confused, say when you make wizard, how do you pass from one View to another View - without using singleton or hacking way. Is there a good Caliburn.Micro way with a good example?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南七夏 2024-10-15 00:41:34

当您使用 Caliburn Micro 时,它会自动将查询字符串中的键映射到视图模型上的属性。

例如,如果您导航到“/Views/ProductView.xaml?Id=42”,则 ProductViewModel.Id 将等于 42。

When you're using Caliburn Micro it will automatically map keys in the query string to properties on the View Model.

For instance if you navigate to "/Views/ProductView.xaml?Id=42" then ProductViewModel.Id will equal 42.

年华零落成诗 2024-10-15 00:41:34

我不能具体代表 Caliburn,但使用 MV-VM 模式,您的视图模型仅通过突变与模型进行通信。

在您的情况下,我希望该模型是库存商品加上一些其他信息的集合,例如当前选择的库存商品。拍照的操作会创建一个新的库存项目,将其添加到集合中,然后将当前选定的库存项目设置为刚刚创建的库存项目。

当您导航到新视图时,将从模型中拾取当前选定的棒项目。

I can't speak for Caliburn specifically, but with the M-V-VM pattern, your View Models communicate via mutations to the Model only.

In your case, I expect that the model is a collection of Stock Items plus some other information, such as the currently selected stock item. The act of taking a photograph creates a new Stock Item, adds it to the collection and then sets the currently selected stock item to be the one that was just created.

When you navigate to your new view, the currently selected stick item will be picked up from the model.

时光是把杀猪刀 2024-10-15 00:41:34

使用nigel给出的方法就可以了。但是不要忘记 ProductView 中的 Id 属性不会在构造函数中设置。它在 OnActivate() 方法中设置。

Using the method given by nigel will work. However don't forget that the Id property in ProductView wont be set in the constructor. It gets set in the OnActivate() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文