Strengtening Caliburn.Micro conversion capabilities with Scal
If one looks into how Caliburn.Micro performs binding between models and views, a number of methods must be considered that play a role.
- Conventions play a role how bindings are derived from naming and involved elements
- VM getter / setter situation plays a role about the supported Binding directions
- Does the VM implement anything Validation-specific?
- Is there a type mismatch between the binding source and target? (classic example: Boolean -> Visibility)
Especially for the last one Scal introduces a configuration hook to provide your own Value Converters. Check out the usage in the sample application:
This is supported by replacing a certain method deep in the bowels of Scal:
The ConventionManager is a Caliburn.Micro class that (through the CM-typical override mechanism of replacing static Func-fields) provides a hook into the binding operations. The key to a value converter is the pair of bound ViewModel-Type to the target UIElement type.
An additional way to leverage Caliburn.Micro’s Binding routine is through the ScalBinding markup extension:
This markup extension will call into the relevant CM Binding-related methods beyond those that deal with the Convention-based binding. That way, the binding shown above will use Scal’s knowledge of known value converters to map the Visibility property to the IsVisible bool.