Caliburn element convention
While trying to learn the source fo开发者_StackOverflowr GameLibrary sample application I saw a line like this:
ConventionManager.AddElementConvention<Rating>(Rating.ValueProperty, "Value", "ValueChanged");
Looked into the source of Caliburn but couldn't really understand what element conventions are.
Can someone describe briefly please?
ConventionManager.AddElementConvention
allows you to establish a set of "default" settings used by the convention system for each type element.
In the case mentioned above, the first parameter value of
Rating.ValueProperty
tells the convention system what the default bindable property is for the element. So, if we have a convention match on aRating
control, we set up the binding against theValueProperty
.The second parameter represents the default property to be used in Action bindings. So, if you create an action binding with an
ElementName
that points to aRating
control, but do not specify the property, we fall back to theValue
property.Finally, the thrid parameter represents the default event for the control. So, if we attach an action to a rating control, but don't specify the event to trigger that action, the system will fall back to the
ValueChanged
event.
These element conventions allow the developer to supply as much or as little information in a variety of situations, allowing the framework to fill in the missing details as approptiate.
精彩评论