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 [email protected].

comments powered by Disqus

Featured

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events