MaxLength for AutoCompleteBox

4 posts, 0 answers
  1. crazy05
    crazy05 avatar
    72 posts
    Member since:
    Sep 2014

    Posted 28 Aug 2015 Link to this post

    Hi,

    I am surprised that there is no MaxLength attribute for RadAutoCompleteBox.

    I want user to free type text and if they don't find what they are looking for, I want to accept the value typed by user.

    I figured out that I am unable to restrict the free typing after max length of 15.

    How can I implement this ?

     

  2. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 31 Aug 2015 Link to this post

    Hi Ram,

    In order to achieve the desired functionality for RadAutoCompleteBox you need to set the MaxLength property of the RadWatermarkTextBox that is placed inside RadAutoCompleteBox. That could be achieved using the ChildrenOfType<T> method as shown below:
    private void batchAutoCompleteBox_Loaded_1(object sender, RoutedEventArgs e)
    {
        var autoCompleteBox = sender as RadAutoCompleteBox;
     
        var waterMarkTextBox = autoCompleteBox.ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault();
        waterMarkTextBox.MaxLength = 15;
    }

    Hopes this helps.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. crazy05
    crazy05 avatar
    72 posts
    Member since:
    Sep 2014

    Posted 31 Aug 2015 in reply to Nasko Link to this post

    Can you please tell on how to do this in MVVM ?

     

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 02 Sep 2015 Link to this post

    Hello Ram,

    Unfortunately, the proposed in my previous response approach is not an appropriate one for pure MVVM scanarios as you should be working with UIElements inside the ViewModel.

    However, I could suggest you another approach how to achieve the desired and at the same time to preserve the MVVM pattern. So, basically what you need to do is to modify the default RadAutoCompleteTextBoxStyle. By setting the desired MaxLength inside it and after that applying that modified Style to the TextBoxStyle the desired could be achieved.

    Please, check the attached sample project that demonstrates that and let us know if it worked for you - please, notice Implicit Styles were used.

    Hopes this helps.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top