I was writing the WPF Bug List series, but when I wrote the third article (the sudden disappearance of ListViewItem), I found the logic of reproducing bugs complicated. And the need for more basic knowledge, if not first explained clearly, is afraid of someone with "do not valiation not on the line" and so on reply to smash the ground. ^_^
This paper analyzes the validation of databinding from the angle of design and application, assuming that the readers have used the validation in databinding. Focuses on the validation of databinding in WPF. For a basic knowledge of data binding, refer to MSDN.
Some people are not happy with data Binding, either WPF or WinForm. Do you think you can control the data synchronization update? If it's just a login box or a program that's written to play, there's absolutely no problem. However, if you are in an enterprise-class program with a large number of hierarchical data structures, manually updating the UI and the back of the database is not only a heavy workload, but also error prone. (WPF certainly has a lot of bugs, but we shouldn't have to.) )
In most cases, simple rule inherited by Valiationrule can do most of the data binding validation. such as Stringrequiredrule,lengthcontraintrule,regexvalidationrule and so on, there is already such a simple rule library project on CodePlex. (What's amazing is that there's not a few lines of code still in beta.)
But for a slightly more complex validation, the general ValidationRule is powerless.
For example, the person class below.
public class person
{public
int maxage = 1000;
public int minage = 0;
public int Age {get; set;}
}
At this point, to validate the age, you take the values of MaxAge and minage. However, this value is not available in the ValidationRule of the. NET Framework 3.0 (3.5 SP1 can be taken in BindingGroup validation). This is also only found in the sibling attribute, if the person has a parent attribute, we want to verify whether the parent exists, we need to get all of them.
At this point we are going to sacrifice the BindingGroup introduced by the. NET Framework 3.5 Dataerrorvalidationrule or the. NET Framework 3.5 SP1. (The unpublished. NET Framework 4.0 is actually a complete version of WPF, with several important components added.) )
PS: In the face of 3.0, 3.5 of the humble, do not want frequent follow-up. NET update is not good. (or the new version is more inviting and pleasant to hear.)