
4 Answers, 1 is accepted
Thank you for contacting us again.
You can set the theme for a specific element by using the GetStyleSheetBuilder method of the ThemeResolutionService. Please refer to the code snippet below:
DefaultStyleBuilder builder = ThemeResolutionService.GetStyleSheetBuilder( |
this.radGridView1, |
typeof(RadButtonElement).FullName, |
"", |
"Office2007Black") as DefaultStyleBuilder; |
if (builder != null) |
{ |
button.Style = builder.Style; |
} |
It is also possible to modify an existing theme for RadGridView and define a different style for the RadButtonElement in it.
Feel free to write us, if you have other questions.
Best wishes,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

So i have a new form, with only one RadButton on it. I use the following code to set the style:
DefaultStyleBuilder builder = ThemeResolutionService.GetStyleSheetBuilder(this.radButton1, typeof(RadButton).FullName, "", "OfficeGlass") as DefaultStyleBuilder;
if (builder != null)
{
this.radButton1.Style = builder.Style;
}
This will work, but it will not work when i try to use my custom theme that i based off of a rad button. I wonder if there is something i haven't done to the stylesheet itself?
In addition, i can't get the buttons to by styled to any theme (custom or built in) when in the gridview. On my original form with the gridview, i have a couple of buttons at the top for testing. They can have themes applied to them (except my custom theme) but the same code in the cellformatting event doesn't change the style even to one of the built-in themes. Is there some way i have to have the themes registered or created or loaded in order to use them for elements in the grid? I'm not sure how to make a theme for the grid the styles buttons in its cells.
Also, what is the significance of the first control passed in? I noticed the other overloads use elements instead of controls.. On my test form, i pass in the button itself, but in the example you gave, you passed in the gridview. In my CellFormatting event, i only have a RadButtonElement and so i can't pass it in unless i use a different overload of GetStyleSheetBuilder method.
Also, since all the buttons in one particular command column will use the same style, can i get the stylesheet on form_load or similar, and then just set it using the CellFormatting event? Do i need to perform that lookup for an individual button?
Thanks again for your help.

One addition, i found a posting which used a helper method to apply a theme to a radprogressbarelement. I copied that methed and it worked to apply the built-in themes to my buttons in the gridview. I still cannot get my custom button theme to work so there must be something wrong with the way i created it or how have it setup.
Thank you for the detailed description of this issue.
All themes created with the Visual Style Builder are applied on a specific control. If you want to apply a theme created for RadButton on RadButtonElement you must have additional style sheet registration.
Add the following code inside the StylesheetRegistrations tag in your theme file:
<RadStylesheetRelation |
ElementType="Telerik.WinControls.UI.RadButtonElement" |
RegistrationType="ElementTypeControlType" |
ElementName="" |
ControlName="" |
ControlType="Telerik.WinControls.UI.RadGridView" /> |
The button theme is specific for the RadButton control. In order to use this theme in other controls you must override the ThemeClassName property of the Control and return the FullName of the RadButton class:
public override string ThemeClassName |
{ |
get |
{ |
return typeof(RadButton).FullName; |
} |
set |
{ |
} |
} |
The first parameter of the GetStyleSheetBuilder method tells the ThemeResolutionService to search for themes registered for a specific control. If you pass only the element parameter to the GetStyleSheetBuilder method, the Control owner of this element is used.
You should call the GetStyleSheetBuilder method inside the CellFormatting event, but you can do this only the first time and save the same StyleSheet instance for all buttons.
Feel free to write us, if you need further assistance.
Sincerely yours,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center