Exemple #1
0
        /// <summary>
        /// Sets the given error string for the given property.
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="error">The error to set.</param>
        protected void SetDataError(string propertyName, string error)
        {
            string givenValue = FormatString(error);

            if (!string.IsNullOrEmpty(givenValue))
            {
                //Add mode
                if (m_specificDataErrors == null)
                {
                    m_specificDataErrors = new Dictionary <string, string>();
                }
                m_specificDataErrors[propertyName] = givenValue;

                if (m_raisePropertyChangedOnError)
                {
                    RaisePropertyChanged(propertyName);
                }
                ErrorsChanged.Raise(this, new DataErrorsChangedEventArgs(propertyName));
                RaisePropertyChanged(() => ContainsErrors);
            }
            else
            {
                //Remove mode
                if (m_specificDataErrors != null)
                {
                    if (m_specificDataErrors.ContainsKey(propertyName))
                    {
                        m_specificDataErrors.Remove(propertyName);
                        if (m_specificDataErrors.Count == 0)
                        {
                            m_specificDataErrors = null;
                        }
                        if (m_raisePropertyChangedOnError)
                        {
                            RaisePropertyChanged(propertyName);
                        }
                        ErrorsChanged.Raise(this, new DataErrorsChangedEventArgs(propertyName));
                        RaisePropertyChanged(() => ContainsErrors);
                    }
                }
            }
        }