Reputation: 46833
In my Silverlight app, I have a button that is bound to a ICommand
that does posts some data to a webservice.
Upon completion, I'd like to have the Command
trigger a callback to the View letting the view know that that specific Command
has completed (I want the View to close).
Is there a way to pass a callback action to a DelegateCommand
?
How else can I notify the View that the ViewModel has completed?
Upvotes: 0
Views: 433
Reputation: 3854
Any communication from the ViewModel to the view should be done, IMHO, through messaging (which is kind of "loosly coupled event" mecanism). So, I think a nice way to do this is to just send a message (you can use the Messenger
class from MVVM Light) from your ViewModel to the view which would close itself. No callback needed.
Hope this helps ;)
Upvotes: 1
Reputation: 1621
You can use couple of different ways to achieve this. One is to inject a view specific service which will perform operations on the User interface layer. The view model will call the specific method on the injected service. One such exampe is demonstrated here.
If you don't want to inject view specific services into the view model, then you can expose an event on the view model like CloseWindow. This event will need to be subscribed in your view.xaml.cs file and from the event handler method you can close the view page.
Hope this helps.
Upvotes: 1