This is a migrated thread and some comments may be shown as answers.

MaxLength for AutoCompleteBox

3 Answers 289 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
crazy05
Top achievements
Rank 1
crazy05 asked on 28 Aug 2015, 12:45 PM

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 ?

 

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 31 Aug 2015, 09:56 AM
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
0
crazy05
Top achievements
Rank 1
answered on 31 Aug 2015, 01:09 PM

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

 

0
Nasko
Telerik team
answered on 02 Sep 2015, 01:43 PM
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
Tags
AutoCompleteBox
Asked by
crazy05
Top achievements
Rank 1
Answers by
Nasko
Telerik team
crazy05
Top achievements
Rank 1
Share this question
or