ErrorProviderMessage with WPF validation

Feb 10, 2010 at 2:40 PM

Hi

I cannot find a way to read wpf validation error messages when using

var errorMsg = myTextBox.ErrorProviderMessage(window);

I have also tried to get the error template and to retrive some info with no luck

 

any thoughts?

 

 

 

ErrorProviderMessage
Coordinator
Feb 19, 2010 at 6:06 PM

Can you please provide some code for application under test to illustrate the issue.

Feb 21, 2010 at 9:30 AM

xaml:

 <TextBox Name="subscriptionName"
                Grid.Column="1"
                Width="200" 
                HorizontalAlignment="Left"
                Margin="3"
                MaxLength="256" 
                Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
                Text="{Binding Path=Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" 
                IsVisibleChanged="subscriptionName_IsVisibleChanged" />

Code of bound entity:

public class Subscription : IDataErrorInfo, INotifyPropertyChanged
    {
        #region Properties

        private string name;
        public string Name 
        {
            get
            {
                return name;
            }
            set
            {
                SetProperty("Name", ref name, value);
            }
        }

        private string description;
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                SetProperty("Description", ref description, value);
            }
        }

.
.
.
.

        #endregion


        #region IDataErrorInfo Members

        string IDataErrorInfo.Error
        {
            get { throw new NotImplementedException(); }
        }

        string IDataErrorInfo.this[string columnName]
        {
            get { return this.GetError(columnName); }
        }

       protected virtual string GetError(string propertyName)
        {
           string result = null;

           switch (propertyName)
            {
                case "Name":
                    if (string.IsNullOrEmpty(Name))
                    {
                        result = Properties.ValidationMessages.SubscriptionNameEmpty;
                    }
                    else if (this.Name.Length > 256)
                    {
                        result = Properties.ValidationMessages.SubscriptionNameLength;
                    }
                    break;
                case "Description":
                    if (string.IsNullOrEmpty(Description))
                    {
                        result = Properties.ValidationMessagesSubscriptionDescriptionEmpty;
                    }
                   
                    break;
               
            }

            return result;
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

       protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

       protected void SetProperty<T>(string name, ref T field, T value)
        {
            if (!object.Equals(field, value))
            {
                field = value;
                OnPropertyChanged(name);
            }
        }

        #endregion
    }

test:

var subscriptionName = window.Get<White.Core.UIItems.TextBox>("subscriptionName");
            NUnit.Framework.Assert.IsNotNull(subscriptionName);

            var errorMsg = subscriptionName.ErrorProviderMessage(window);

Coordinator
Mar 2, 2010 at 9:55 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.