MaxLength and CharacterCasing

3 posts, 0 answers
  1. Peter Taylor
    Peter Taylor avatar
    4 posts
    Member since:
    Dec 2009

    Posted 04 Feb 2010 Link to this post

    When the RadComboBox is in IsEditable mode, how do I set the MaxLength and CharacterCasing properties of the TextBox used for entering data?
  2. Peter Taylor
    Peter Taylor avatar
    4 posts
    Member since:
    Dec 2009

    Posted 04 Feb 2010 Link to this post

    I think I may have found the answer.

    Create an Attached Property in a helper class:


        public class EditableComboBox
        {

            public static int GetMaxLength(DependencyObject obj)
            {
                return (int)obj.GetValue(MaxLengthProperty);
            }

            public static void SetMaxLength(DependencyObject obj, int value)
            {
                obj.SetValue(MaxLengthProperty, value);
            }

            // Using a DependencyProperty as the backing store for MaxLength.
            public static readonly DependencyProperty MaxLengthProperty =
                DependencyProperty.RegisterAttached("MaxLength", typeof(int), typeof(EditableComboBox), new UIPropertyMetadata(OnMaxLengthChanged));


            private static void OnMaxLengthChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
            {
                var comboBox = obj as Telerik.Windows.Controls.RadComboBox;
                if (comboBox == null)
                {
                    return;
                }

                comboBox.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
                    (DispatcherOperationCallback)delegate
                    {
                        TextBox textBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox);

                        if (textBox != null)
                        {
                            textBox.SetValue(TextBox.MaxLengthProperty, e.NewValue);
                        }

                        return null;
                    }
                    , null);
            }

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

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

            // Using a DependencyProperty as the backing store for CharacterCasing.
            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
                    {
                        TextBox textBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox);

                        if (textBox != null)
                        {
                            textBox.SetValue(TextBox.CharacterCasingProperty, e.NewValue);
                        }

                        return null;
                    }
                    , null);
            }

    Then declare it in XAML:

            <ti:RadComboBox IsEditable="True" local:EditableComboBox.MaxLength="20"/>

    where 'local' is the location of the class in your code






  3. UI for WPF is Visual Studio 2017 Ready
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 04 Feb 2010 Link to this post

    Hi Peter,

    Thank you for contacting us.

    We are glad that you have found a solution yourself. Your Telerik points have been updated.

    If you need any further assistance concerning our controls please feel free to contact us again.

    Greetings,
    Konstantina
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Back to Top