Search code examples
silverlightunity-containercaliburn

Caliburn : How to get an async result back to viewmodel and then view


I have a ContainerCommand (which is registered in Unity) which calls a web service asynchronously. What I want is the result of the web service to be some how propagated back to the view model and then view. The app is written in Silverlight.

How can I do this?

JD.


Solution

  • Commands in Caliburn can take parameters. So you might consider passing the ViewModel into the command. Then, the command can update the VM, which in turn updates the View. Chances are, your VM is set to the DataContext, so you could do something like this:

    Message.Attach="ContainerCommand MyCommand($dataContext)"

    Also, since your command is created via the container, if your VM is also registered in the container as a singleton, you could have the VM injected into the command; then update as above.