Styling custom controls

2 posts, 0 answers
  1. John
    John avatar
    19 posts
    Member since:
    May 2009

    Posted 11 Jul 2009 Link to this post

    Greetings,

    I've been tasked with setting up a Silverlight control set for our company's developers for use throughout multiple projects. Each control in this set will wrap either a Telerik or standard Silverlight control. For example, the control set will contain an ESCButton class which derives from System.Windows.Controls.Button, an ESCCheckBox class which derives from System.Windows.Controls.CheckBox, an ESCComboBox which derives from RadComboBox, etc - you get the idea...We're trying to take this approach in case a particular control needs some non-standard functionality that we can implement and all projects will be able to benefit with no additional effort. Make sense?

    To make matters a little more interesting, these controls need to share a common 'theme' that will be customized at a later date... As a starting point, I took the Generic.xaml from the Telerik.Windows.Themes.Vista dll and placed it inside the assembly for our custom control set under a folder named Themes. My question is... Without modifying each Style's TargetType attribute in the massive Generic.xaml (which exceeds 20,000 lines), is there any way to link the style of the base controls (e.g. System.Windows.Controls.Button, System.Windows.Controls.CheckBox, RadComboBox) with our extended controls? Hopefully, the following snippet will help you understand what I am trying to accomplish:

    public class ESCCheckBox : System.Windows.Controls.CheckBox
    {
            /// <summary>
            /// Initializes a new instance of the ESCCheckBox class.
            /// </summary>
            public ESCCheckBox()
            {
                this.DefaultStyleKey = typeof(System.Windows.Controls.CheckBox);
            }
    }

    Unfortunately, the snippet above causes the ESCCheckBox to use the default style of the System.Windows.Controls.CheckBox instead of the one defined in the Generic.xaml (Vista theme). Note that I can update the TargetType attribute on the CheckBox style in the Generic.xaml to something like TargetType="local:ESCCheckBox" and everything works great. But, doing this for all of our controls for multiple themes and making it all work is quite a task!

    Any thoughts on how i could use the base control's style as-is from the Generic.xaml?
  2. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 16 Jul 2009 Link to this post

    Hi John,

    There are two ways to do this that I can think of. One of them is the to change Style's TargetType in our Generic.xaml which you want to avoid. Note that we are making changes to our theming mechanism and optimizing it. So in a week for the SP1 there will be some changes and is also expected the size of the Generic.xaml to be significantly decreased.

    The other way is to set specifically Vista theme in the constructor of each control and point to where your resources are. This will allow the proper theme to be set when the control is loaded.

    I would advise you to wait for  SP1 and see what the changes are and maybe it won't be that much work to modify the Generic.xaml then.

    Regards,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top