Apply Theme to RadButtonElement

5 posts, 0 answers
  1. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 24 Jan 2008 Link to this post

    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!
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 25 Jan 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 25 Jan 2008 Link to this post

    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.

  5. Sean McConnell
    Sean McConnell avatar
    38 posts
    Member since:
    Aug 2007

    Posted 25 Jan 2008 Link to this post

    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.

  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 28 Jan 2008 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready