views:

443

answers:

1

A note - the classes I have are EntityObject classes!

I have the following class:

public class Foo
{
    public Bar Bar { get; set; }
}

public class Bar : IDataErrorInfo
{
    public string Name { get; set; }

    #region IDataErrorInfo Members
    string IDataErrorInfo.Error
    {
        get { return null; }
    }

    string IDataErrorInfo.this[string columnName]
    {
        get
        {
            if (columnName == "Name")
            {
                return "Hello error!";
            }
            Console.WriteLine("Validate: " + columnName);
            return null;
        }
    }
    #endregion
}

XAML goes as follows:

<StackPanel Orientation="Horizontal" DataContext="{Binding Foo.Bar}">
     <TextBox Text="{Binding Path=Name, ValidatesOnDataErrors=true}"/>
</StackPanel>

I put a breakpoint and a Console.Writeline on the validation there - I get no breaks. The validation is not executed. Can anybody just press me against the place where my error lies?

A: 

You forgot to implement INotifyPropertyChanged on the 'Bar' class, then only the binding system will trigger the setter.

So your 'Name' property should most likely be.

public string Name 
    { 
          get{ return _name; } 
      set
      {
          _name = value;
          RaisePropertyChanged("Name"); // Or the call might OnPropertyChanged("Name");
      }
    }
Jobi Joy
But as I mentioned above - both Foo and Bar and child classes of EntityObject class (which does notify OnPropertyChange).
Jefim
I was actually thinking that thie EntityObject parent class can influence this somehow, as the IDataErrorInfo usually works fine.
Jefim