How To Create Advanced Custom Controls
Stuff clipped from the custom control guide.
Here's how the Border control defines its Background property:
The AvaloniaProperty.Register method also accepts a number of other parameters:
defaultValue: This gives the property a default value. Be sure to only pass value types and immutable types here as passing a reference type will cause the same object to be used on all instances on which the property is registered.inherits: Specified that the property's default value should come from the parent control.defaultBindingMode: The default binding mode for the property. Can be set toOneWay,TwoWay,OneTimeorOneWayToSource.validate: A validation/coercion function of typeFunc<TOwner, TValue, TValue>. The function accepts the instance of the class on which the property is being set and the value and returns the coerced value or throws an exception for an invalid value.
A styled property is analogous to a
DependencyPropertyin other XAML frameworks.
The naming convention of the property and its backing AvaloniaProperty field is important. The name of the field is always the name of the property, with the suffix Property appended.