/// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="message">Message from the model.</param>
        public ModelErrorListItemViewModel(ViewModelStore viewModelStore, ModelValidationMessage message)
            : base(viewModelStore, message.MessageId, ConvertCategory(message.Type), message.Description)
        {
            this.message = message;

            if (message.Source is IDomainModelOwnable)
            {
                if ((message.Source as IDomainModelOwnable).DomainElementHasName)
                {
                    this.SourceDisplayName = (message.Source as IDomainModelOwnable).DomainElementName;
                    
                    DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
                    this.ViewModelStore.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(info, message.Source.Id, OnNamePropertyChanged);
                }
                else
                {
                    this.SourceDisplayName = (message.Source as IDomainModelOwnable).DomainElementTypeDisplayName;
                }
            }

            /*
            if (this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.HasName(message.Source))
            {
                this.SourceDisplayName = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetName(message.Source);

                DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
                this.ViewModelStore.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(info, message.Source.Id, OnNamePropertyChanged);
            }
            else
                this.SourceDisplayName = this.ViewModelStore.GetDomainModelServices(message.Source).ElementTypeProvider.GetTypeDisplayName(message.Source);
            */

            this.ViewModelStore.EventManager.GetEvent<ModelElementDeletedEvent>().Subscribe(message.Source.Id, OnElementDeleted);
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="message">Message from the model.</param>
        public ModelErrorListItemViewModel(ViewModelStore viewModelStore, ModelValidationMessage message)
            : base(viewModelStore, message.MessageId, ConvertCategory(message.Type), message.Description)
        {
            this.message = message;

            if (message.Source is IDomainModelOwnable)
            {
                if ((message.Source as IDomainModelOwnable).DomainElementHasName)
                {
                    this.SourceDisplayName = (message.Source as IDomainModelOwnable).DomainElementName;

                    DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
                    this.ViewModelStore.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(info, message.Source.Id, OnNamePropertyChanged);
                }
                else
                {
                    this.SourceDisplayName = (message.Source as IDomainModelOwnable).DomainElementTypeDisplayName;
                }
            }

            /*
             * if (this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.HasName(message.Source))
             * {
             *  this.SourceDisplayName = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetName(message.Source);
             *
             *  DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
             *  this.ViewModelStore.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(info, message.Source.Id, OnNamePropertyChanged);
             * }
             * else
             *  this.SourceDisplayName = this.ViewModelStore.GetDomainModelServices(message.Source).ElementTypeProvider.GetTypeDisplayName(message.Source);
             */

            this.ViewModelStore.EventManager.GetEvent <ModelElementDeletedEvent>().Subscribe(message.Source.Id, OnElementDeleted);
        }
        /// <summary>
        /// Clean up.
        /// </summary>
        protected override void OnDispose()
        {
            if (message.Source is IDomainModelOwnable)
            {
                if ((message.Source as IDomainModelOwnable).DomainElementHasName)
                {
                    try
                    {
                        DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
                        this.ViewModelStore.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Unsubscribe(info, message.Source.Id, OnNamePropertyChanged);
                    }
                    catch {}
                }
            }

            this.ViewModelStore.EventManager.GetEvent <ModelElementDeletedEvent>().Unsubscribe(message.Source.Id, OnElementDeleted);

            this.message = null;

            base.OnDispose();
        }
        /// <summary>
        /// Clean up.
        /// </summary>
        protected override void OnDispose()
        {
            if (message.Source is IDomainModelOwnable)
                if ((message.Source as IDomainModelOwnable).DomainElementHasName)
                {
                    try
                    {
                        DomainPropertyInfo info = this.ViewModelStore.GetDomainModelServices(message.Source).ElementNameProvider.GetNamePropertyInfo(message.Source);
                        this.ViewModelStore.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Unsubscribe(info, message.Source.Id, OnNamePropertyChanged);
                    }
                    catch{}
                }

            this.ViewModelStore.EventManager.GetEvent<ModelElementDeletedEvent>().Unsubscribe(message.Source.Id, OnElementDeleted);

            this.message = null;

            base.OnDispose();
        }