This is a migrated thread and some comments may be shown as answers.

Styling custom controls

1 Answer 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 11 Jul 2009, 02:48 PM
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?

1 Answer, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 16 Jul 2009, 08:55 AM
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.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Share this question
or