The Command Pattern in .NET: Listing 2

Full source code for the MessageViewModel class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Input;
 
namespace VSMCommandPatternDemo
{
    public class MessageViewModel : INotifyPropertyChanged
    {
        private string _myMessage;
 
        public string MyMessage
        {
            get { return _myMessage; }
            set
            {
                if (_myMessage != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MyMessage"));
                }
 
                _myMessage = value;
            }
        }
 
        public ICommand MessageBoxCommand { get; set; }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public MessageViewModel()
        {
            MessageBoxCommand = new Commands.MessageBoxCommand(this);
        }
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at vogelvision@gmail.com.