Inherit themes from RadControls

Article Info

Rating: 5

Article information

Article relates to

 RadControls for WinForms

Created by

 Nikolay Diyanov

Last modified

 Feb 17, 2009

Last modified by

 Nikolay Diyanov



HOW-TO
Inherit the original control themes from RadControls

SOLUTION
When you inherit from a RadControl (or any RadControl descendant), the original control themes are not automatically inherited. The good thing is that this behavior can be overridden very easily by overriding the ThemeClassName property of the descendant of RadControl

C#

public class RadCustomButton : RadButton  
    {  
        public override string ThemeClassName  
        {  
            get 
            {  
                return typeof(RadButton).FullName;  
            }  
        }  
    } 

VB.NET

Public Class RadCustomButton  
    Inherits RadButton  
 
    Public Overrides Property ThemeClassName() As String 
        Get 
            Return GetType(RadButton).FullName  
        End Get 
        Set(ByVal value As String)  
 
        End Set 
    End Property 
End Class 

The example above uses RadButton as a base class. Since the themes depend on the type of the themed class (which is changed when you inherit), using the described override makes base control themes available in the descendant control. The sample projects below demonstrate the approach.

When you inherit from a RadElement descendant (for example RadButtonElement), you need to override the ThemeEffectiveType property. This will allow you to have the styling applied to the instance of your custom element class:

public class MyRadButtonElement : RadButtonElement     
{     
    protected override Type ThemeEffectiveType     
    {     
        get    
        {     
            return typeof(RadButtonElement);     
        }     
    }     

Public Class MyRadButtonElement  
    Inherits RadButtonElement  
    Protected Overrides ReadOnly Property ThemeEffectiveType() As Type  
        Get 
            Return GetType(RadButtonElement)  
        End Get 
                Set(ByVal value As Type  
    
                End Set    
    End Property 
End Class 

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.