开发者

Communicating between ViewModels in Windows Phone 7

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 e开发者_StackOverflow社区nters.

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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜