Restrictions and Tips for Creating a Silverlight Control
When creating a custom control for Silverlight, follow the tips below for standards of use.
- The control must derive from
System.Windows.FrameworkElement
. - The control must have a parameterless constructor.
- Any property that you want to be able to configure through the Designer should be exposed as a standard Silverlight dependency property.
- The property can be driven by a binding or expression in the Silverlight Designer.
- For simple data types, the Designer provides a default property editor to all users so that a literal value for the property can be configured.
- For data types where the default property editor is not sufficient, custom data type editors can be created. For more information, see Create a Custom Data Type Editor for the Silverlight Designer.
- These properties should be of a data type that can be serialized to XAML. Note: There is a known issue with using GUID as a data type.
- For complex data types, if a property using this type is not being persisted, it may help to initialize the default value of the property using the SetValue method as described below.
- If you want the property to be configurable through the designer, the Editor-Browsable attribute should be set to Always or Advanced.
- The Category attribute can be used to specify the category this property appears in.
"Please enter in the values below."
A different value for this property can be specified through the default property editor provided. In this case, it is a simple textbox. In addition, this property value can be driven by a binding or expression in the Silverlight Designer.
public static readonly DependencyProperty InstructionsProperty
=
DependencyProperty.Register("Instructions", typeof(string),
typeof(MyCustomControl), new
PropertyMetadata("Please enter in the values below."));
[EditorBrowsable(EditorBrowsableState.Always),
Category("Definition")]
public String Instructions
{
get { return GetValue(InstructionsProperty) as
String; }
set { SetValue(InstructionsProperty, value); }
}
public HelpfulDataGrid()
{
SetValue(PopupDataProperty, new CustomList());
//Rest of constructor code here
}