Self validating controls
A converter class converts data from one type to another during binding by implementing the Convert and Convert Back methods of the mentioned interface.Once you have created a converter class you will typically add it as a resource in XAML with a unique x: Key attribute and then reference it from the binding as a Static Resource: (string) to a dependency property of type string you don’t necessarily need to use a converter as the default conversion will automatically apply the To String() method on the value of the source property.
Below is an example of a simple service with a single method that validates a username by first querying a database to determine whether it is already in use or not and then checks the length of it and finally determines whether it contains any illegal characters by using a regular expression.
Setting the property to this value means that the value of the source property only gets updated when you explicitly call the Binding Expression. You will typically never use this approach in an MVVM application though.
If you want to bind a view model property of a specific type to a dependency property in the view of a different type you may need to implement a custom converter class by implementing the interface and setting the Converter property of the binding to an instance of this.
Provided that the view model has a property called “Name”, you bind it to a Text Box’s Text property in XAML the following way: Besides the path that specifies the name of the property to bind to, the binding must also have a source object.
If you don’t specify a source explicitly by setting the Source property of the binding, it will inherit the Data Context from its parent element to use as its source.