ViewModel to translate domain messages to view events

Here is an example of a ViewModel that translates domain messages to view events:

class GameViewModel : INotifyPropertyChanged, IListener<BoardChanged>
{
 public event PropertyChangedEventHandler PropertyChanged = delegate { }; 

 public GameViewModel()
 {
  var messageBus = ServiceLocator.MessageBus;
  messageBus.Subscribe<BoardChanged>(this);
 }

 void IListener<BoardChanged>.Handle(BoardChanged message)
 {
  PropertyChanged("Board");
 }
}

This entry was posted on Tuesday, October 13th, 2009 at 17:18 and is filed under C#, Silverlight, WPF. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply