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

RadButtonElement subclass doesn't have correct style

1 Answer 138 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Michael asked on 09 Apr 2009, 07:38 PM
If I subclass RadButtonElement, the subclass no longer has the same style applied as a pure RadButtonElement.  Here's the simple code snippet:

            ... 
            panel.Children.Add(new RadButtonElement() { Text = "RadButtonElement" }); 
            panel.Children.Add(new MyRadButtonElement() { Text = "MyRadButtonElement" }); 
        } 
 
        class MyRadButtonElement : RadButtonElement 
        { 
        } 
 
 

Can you tell me how to make my RadButtonElement have the same default style (e.g. background color, mouse rollover) as a regular RadButtonElement?

Thanks,
Michael Hewitt
Precision Software Design, LLC

For reference, here is the full body of my Form.OnLoad function:

        void Form1_Load(object sender, EventArgs e) 
        { 
            // Create element container to fill form 
            RadPanel elementsContainer = new RadPanel(); 
            this.Controls.Add(elementsContainer); 
            elementsContainer.Dock = DockStyle.Fill; 
            elementsContainer.BeginInit(); 
            elementsContainer.EndInit(); 
 
            // Create scroll viewer for scrollbar support 
            RadScrollViewer scrollViewer = new RadScrollViewer(); 
            elementsContainer.PanelElement.Children.Add(scrollViewer); 
 
            // Create panel to stack buttons 
            StackLayoutPanel panel = new StackLayoutPanel(); 
            scrollViewer.Viewport = panel; 
            panel.Orientation = Orientation.Vertical; 
            panel.Children.Add(new RadButtonElement() { Text = "RadButtonElement" }); 
            panel.Children.Add(new MyRadButtonElement() { Text = "MyRadButtonElement" }); 
        } 
 
        class MyRadButtonElement : RadButtonElement 
        { 
        } 
 
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 10 Apr 2009, 03:15 PM
Hello Michael,

Thank you for the question.

When you make a class which descends from a RadButtonElement class, you should override the ThemeEffectiveType and return the type of the parent class. This will allow you to use the theming mechanism for your class:
public class MyRadButtonElement : RadButtonElement  
{  
    protected override Type ThemeEffectiveType  
    {  
        get 
        {  
            return typeof(RadButtonElement);  
        }  
    }  
}   

If you have additional questions, feel free to contact me.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Michael
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
Share this question
or