1
Vote

ViewModelDetailBase IsValid binding update

description

Hey,


I noticed if i bind my button to the IsValid property of a ViewModelDetailBase (SimpleMvvmToolkit-SL5) it doesn't get updated when there is a validation error.
I think the problem is in the setter of the Model in that class.

The code:
if (notifyDataErrorInfo != null)
   notifyDataErrorInfo.ErrorsChanged += (EventHandler<DataErrorsChangedEventArgs>) ((s, ea) =>
      {
          if (!this.ModelMetaProperties.Contains(ea.PropertyName))
              return;
           BindingHelper.InternalNotifyPropertyChanged("IsValid", (object) this, this.propertyChangedField, this.Dispatcher);
          });
Description of ModelMetaProperties:
Model meta-properties which should be ignored when handling property changed events,
and when dirty-checking or performing validation.
While debugging i notice that ea.PropertyName is the name of the property that has a error.
That name will normaly not be in the ModelMetaProperties list.
Resulting that BeginHelper wont get called.
If i compair it with the code in ViewModelDetailBaseCore i see that it is implemented correct there.
So i think you should remove the ! operator in if (!this.ModelMetaProperties.Contains(ea.PropertyName)).


Greetings
Skoucail

comments

Skoucail wrote Apr 3, 2014 at 1:06 PM

The code i linked was from the .dll.
This is the code like its posted on codeplex:
In ViewModelDetailBase (for SL5):
if (ModelMetaProperties.Contains(ea.PropertyName))
                        {
                            BindingHelper.InternalNotifyPropertyChanged
                                ("IsValid", this, propertyChangedField, Dispatcher);
                        }
In ViewModelDetailBaseCore (common)
if (!_modelMetaProperties.Contains(ea.PropertyName))
                    {
                        BindingHelper.InternalNotifyPropertyChanged
                            ("IsDirty", this, propertyChangedField, Dispatcher);
                    }
As you can see, i think you forgot the ! operator in ViewModelDetailBase (for SL5).

tonysneed wrote Jun 6, 2014 at 10:58 PM

Good catch. I'll put this on the bug fix list for the next release, which we're working on.

Cheers,
Tony