Home / Community & Support / Knowledge Base / RadControls for WinForms / General and Installation / Using Behaviors to add custom functionality to any RadElement

Using Behaviors to add custom functionality to any RadElement

Article Info

Rating: Not rated

 

Article information

Article relates to

RadControls for WinForms Q4 2006 SP2

Created by

Iordan Pavlov, Telerik

Last modified

Feb. 21, 2207

Last modified by

Iordan Pavlov, Telerik


 
HOW-TO
Use Behaviors to add custom functionality to any RadElement

SOLUTION
You can easily add custom functionality to any RadElement using behaviors. Imagine the following scenario:

You have a ButtonElement with hidden border:

this.radButton1.ButtonElement.BorderElement.Visibility = ElementVisibility.Hidden; 

Let’s say you want the border to become visible on MouseOver. This can be accomplished by writing a simple behavior:

public class ButtonBorderBehavior : PropertyChangeBehavior        
    {        
        public ButtonBorderBehavior()        
            : base(RadElement.IsMouseOverProperty)        
        {        
        }        
       
        public override void OnPropertyChange(RadElement element, RadPropertyChangedEventArgs e)        
        {        
            RadButtonElement button = (RadButtonElement)element;        
       
            if (button.ShowBorder)        
            {        
                button.BorderElement.Visibility =         
                    (bool)e.NewValue ? ElementVisibility.Visible : ElementVisibility.Hidden;        
            }        
        }        
    }       
    
 

The only thing left is to attach this custom behavior to the ButtonElement (for example while loading the form):

this.radButton1.ButtonElement.AddBehavior(new ButtonBorderBehavior()); 

Comments

There are no comments yet.
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.