Instead, their values must be supplied as arguments
to the Register() method.
The following code shows an example of how a DependencyPropery must be created.
Here, the FrameworkElement class uses a shared constructor to initialize the MarginProperty:
Shared Sub New()
Dim metadata As new FrameworkPropertyMetadata( _
New Thickness(), FrameworkPropertyMetadataOptions.AffectsMeasure)
MarginProperty = DependencyProperty.Register("Margin", _
GetType(Thickness), GetType(FrameworkElement), metadata, _
AddressOf FrameworkElement.IsMarginValid)
...
End Sub
There are two steps involved in registering a dependency property. First, you create a
FrameworkPropertyMetadata object that indicates what services you want to use with your
dependency property (such as support for data binding, animation, and journaling). Next,
you register the property by calling the shared DependencyProperty.Register() method. At
this point, you are responsible for supplying a few key ingredients:
??? The property name (Margin in this example)
??? The data type used by the property (the Thickness structure in this example)
??? The type that owns this property (the FrameworkElement class in this example)
??? Optionally, a FrameworkPropertyMetadata object with additional property settings
??? Optionally, a callback that performs validation for the property
The first three details are all straightforward.
Pages:
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288