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

Apply Theme to RadButtonElement

4 Answers 364 Views
Themes and Visual Style Builder
This is a migrated thread and some comments may be shown as answers.
Sean McConnell
Top achievements
Rank 1
Sean McConnell asked on 24 Jan 2008, 11:43 PM
I posted earlier about issues with the CommandButton and your suggestion of "hiding" the existing button and creating a new one has worked well and cleared up a number of issues.  Now, i would like to apply a theme to the button i have inserted, but am unable to do so to a RadButtonElement and i can't add a RadButton (which can have a theme applied) to the cell.  How can i set the theme for this button or other buttons in the grid?  If i cant, how can i set the appearance for the different states of the button (isPressed,isMouseOver, etc) like i can using the visual design tools?  Can those be set through code?  Thanks for your help!

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 25 Jan 2008, 01:02 PM
Hello Randall Kohltfarber,

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
0
Sean McConnell
Top achievements
Rank 1
answered on 25 Jan 2008, 05:56 PM
Thanks again for the quick response.  I couldn't seem to get that code to work.  I figured i'd try it outside of the gridview and my button was a custom class that inherits from RadButtonElement and overrides ThemeEffectiveType.

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.

0
Sean McConnell
Top achievements
Rank 1
answered on 25 Jan 2008, 06:45 PM

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.

0
Jack
Telerik team
answered on 28 Jan 2008, 01:00 PM
Hi Randall,

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
Tags
Themes and Visual Style Builder
Asked by
Sean McConnell
Top achievements
Rank 1
Answers by
Jack
Telerik team
Sean McConnell
Top achievements
Rank 1
Share this question
or