Sunday, August 26, 2012

Notification to View from ViewModel using MVVM Light

Notification to View from ViewModel using MVVM Light

In my silverlight application I need to send a notification from a ViewModel to a View. In response to it a method on a UI control should be called. I know about 2 ways to accomplish this:

1) Raise an event in the ViewModel and handle it in the View's code behind.
2) Send a message from the ViewModel (using the MVVM Light messaging support) and respond to this message in the View's code behind.

I'd like to know if there is a way to accomplish this without using code in the View's code behind, for instance through some kind of data binding in the XAML?

Please share any ideas.

Answers & Comments...

Answer: 1

Yes...you can do it with the help of a dependency property.

  1. Create a dependency property for that view (Make it boolean type since we just need this property to call another view method).
  2. In its property changed call back, make provisions to call your required view method.
  3. Then bind the DependencyProperty with a propert in ViewModel.
  4. So when you need the view to be updated, just set the binded Property mentioned above, this will fire the property changed call back of Dependency property and form there your required view method will be called.
by : Eldhose M Babuhttp://stackoverflow.com/users/1618885




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog