AddDependantProperty - WPF

AddDependantProperty - WPF

Old forum URL: forums.lhotka.net/forums/t/3381.aspx


marciak posted on Wednesday, August 15, 2007

I am just begininng to use AddDependantProperty and as a test, I added a test rule that if a last name is entered a first name must also be entered.  If I enter a last name, the first name and last name controls are both being correctly marked as invalid.  When I enter the first name, the first name control is being marked as valid but the last name control continues to be marked as invalid.  Has anyone else seen this behavior?

 

Thanks,

marciak

Curelom replied on Wednesday, August 15, 2007

I have been having difficulty with adddependentproperty and the csla wpf validator as well, though I haven't spent enough time yet in figuring out the exact misbehavior that is occuring.  It's been my experience so far that the validator does not fire for me at all when these rules are invalidated.

McManus replied on Wednesday, August 15, 2007

marciak:

I am just begininng to use AddDependantProperty and as a test, I added a test rule that if a last name is entered a first name must also be entered.  If I enter a last name, the first name and last name controls are both being correctly marked as invalid.  When I enter the first name, the first name control is being marked as valid but the last name control continues to be marked as invalid.  Has anyone else seen this behavior?

Marciak,

Probably you have set up the rules as follows:

   ValidationRules.AddRule(TestRule, "FirstName");
   ValidationRules.AddRule(TestRule, "LastName");
   ValidationRules.AddDependantProperty("LastName", "FirstName");

The first line says that the TestRule must be executed when FirstName changes, the second line says that TestRule must be executed when LastName changes and the third line says that when LastName changes, all rules coupled to FirstName must be excuted as well.

So, when you fill in LastName, TestRule is executed twice (once for LastName and once for FirstName). If you then fill in FirstName, TestRule is only executed for FirstName, marking the FirstName property as being valid. However, LastName is still invalid because it still has a BrokenRule attached to it.

Changing the third line to:

   ValidationRules.AddDependantProperty("LastName", "FirstName", true);

should solve your problem, because now it says: When LastName changes, execute all rules coupled to FirstName as well and when FirstName changes, execute all rules coupled to LastName as well.

Hope this helps!

Herman

Curelom replied on Wednesday, August 15, 2007

This doesn't seem to be my problem.  My Library fires correctly in non wpf apps.  I have debugged this in wpf and the validation error does fire, but it looks like the Validator isn't catching it.  I think it might have something to do with _haveRecentChange in the Validator is returning false for all the bindings.  It does return true if I use a regular validation rule.

marciak replied on Thursday, August 16, 2007

Herman,

Thanks for your reply.  I do have the third line coded with True for the isBiDirectional parameter.

Marciak

Copyright (c) Marimer LLC