Edit this page

Set CharacterCasing Property of the Input Area

The purpose of this tutorial is to show you how to set the CharacterCasing property of the InputArea of an editable RadComboBox(RadComboBox's IsEditable property is set to True).

The idea in this case is to create a new Attached Property in a helper class.

C#

public class EditableComboBox
{
    public static int GetCharacterCasing( DependencyObject obj )
    {
        return ( int )obj.GetValue( CharacterCasingProperty );
    }

    public static void SetCharacterCasing( DependencyObject obj, int value )
    {
        obj.SetValue( CharacterCasingProperty, value );
    }

    public static readonly DependencyProperty CharacterCasingProperty =
        DependencyProperty.RegisterAttached( "CharacterCasing", typeof( int ), typeof( EditableComboBox ), new UIPropertyMetadata( OnCharacterCasingChanged ) );

    private static void OnCharacterCasingChanged( DependencyObject obj, DependencyPropertyChangedEventArgs e )
    {
    }
}

VB.NET

Public Class EditableComboBox
    Public Shared Function GetCharacterCasing(ByVal obj As DependencyObject) As Integer
        Return CInt(obj.GetValue(CharacterCasingProperty))
    End Function
    Public Shared Sub SetCharacterCasing(ByVal obj As DependencyObject, ByVal value As Integer)
        obj.SetValue(CharacterCasingProperty, value)
    End Sub
    Public Shared ReadOnly CharacterCasingProperty As DependencyProperty = DependencyProperty.RegisterAttached("CharacterCasing", GetType(Integer), GetType(EditableComboBox), New UIPropertyMetadata(OnCharacterCasingChanged))
    Private Shared Sub OnCharacterCasingChanged(ByVal obj As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
    End Sub
End Class

In the OnCharacterCasingChanged() event handler you should perform the following step.

  • Get the target combobox.

  • Get the PART_EditableTextBox element from its template.

  • The PART_EditableTextBox is a TextBox and you can easily set its CharacterCasing property.

C#

public class EditableComboBox
{
    public static int GetCharacterCasing( DependencyObject obj )
    {
        return ( int )obj.GetValue( CharacterCasingProperty );
    }
    public static void SetCharacterCasing( DependencyObject obj, int value )
    {
        obj.SetValue( CharacterCasingProperty, value );
    }
    public static readonly DependencyProperty CharacterCasingProperty =
        DependencyProperty.RegisterAttached( "CharacterCasing", typeof( int ), typeof( EditableComboBox ), new UIPropertyMetadata( OnCharacterCasingChanged ) );
    private static void OnCharacterCasingChanged( DependencyObject obj, DependencyPropertyChangedEventArgs e )
    {
        var comboBox = obj as Telerik.Windows.Controls.RadComboBox;
        if ( comboBox == null )
        {
            return;
        }
        comboBox.Dispatcher.BeginInvoke( DispatcherPriority.Loaded,
            ( DispatcherOperationCallback )delegate
            {
                var childrenCount = VisualTreeHelper.GetChildrenCount( comboBox );
                if ( childrenCount > 0 )
                {
                    var rootElement = VisualTreeHelper.GetChild( comboBox, 0 ) as FrameworkElement;
                    TextBox textBox = ( TextBox )rootElement.FindName( "PART_EditableTextBox" );
                    if ( textBox != null )
                        textBox.SetValue( TextBox.CharacterCasingProperty, ( CharacterCasing )e.NewValue );
                }
                return null;
            }
            , null );
    }
}

Finally set the property in XAML.

XAML

<telerik:RadComboBox IsEditable="True" example:EditableComboBox.CharacterCasingProperty="1"/>

Note that you have to set the RadComboBox's IsEditable property to True.