Wednesday, June 11, 2008

Silverlight 2 Beta 2 - how to set built-in style for custom controls from generic.xaml

Built-In Style of Controls

The built-in style for a control is now determined by looking at the DefaultStyleKey property. This property defaults to null (which means no built-in style will be used).

If a control class wishes to provide a built-in style that is different from its parent, it should set the DefaultStyleKey in the control constructor. This change ultimately enables the scenario where a developer wants to subclass a control and add functionality, but does not wish to change the control's built-in look.

Example: Button sets DefaultStyleKey

public class Button : Control
{
public Button() : base()
{
...
DefaultStyleKey = typeof(Button);
}
}

for more details : http://msdn.microsoft.com/en-us/library/cc645049(VS.95).aspx

No comments: