| Joe Wood's profileMeasured and ArrangedBlogLists | Help |
|
September 03 Gotchas with Custom Controls in WPFHere's a few lessons learnt whilst developing WPF usercontrols, custom controls and custom ItemsControls. Failed to recognize Dependency Property or Attached Property.Make sure that the static property is defined for on the class it is being used. For a dependency property called 'Custom' with a default value of 1.0: public static DependencyProperty CustomProperty = DependencyProperty.Register("Custom", typeof(int),
Also make sure that the class level accessors have been added: public int Custom For Attached Properties use RegisterAttached:
The public methods : public static void SetCustom(UIElement element, int value) public static int GetCustom(UIElement element) Error Loading XAML after adding a Dependency/Attached PropertyCheck that datatype of the default value. Make sure that it matches the type of the property (1.0 for a double versus 1 - which is an integer). Implicit Styles not being picked up for the custom control:When defining a style with a key of the data type of the custom control all the settings are ignored. First, check that the default resource key has been defined in the custom control. Add the following public static constructor, this indicates that the default style for this control should use the Type object of MyClass :
static MyClass() Also, do not set the Style property of the custom control in the XAML definition. To apply a default style use a local style definition with a key of the type object. Your Custom Control is not being created as the item in the ItemsControlTo instruct an ItemsControl derived class to create a specific custom control for databound items you need to override two virtuals: protected override DependencyObject GetContainerForItemOverride() protected override bool IsItemItsOwnContainerOverride(object item) TrackbacksThe trackback URL for this entry is: http://joewood.spaces.live.com/blog/cns!ED8F6AE13739FF99!160.trak Weblogs that reference this entry
|
|
|