Set MaxLength Property of the Input Area
The purpose of this tutorial is to show you how to set the MaxLength property of the InputArea of editable RadComboBox (RadComboBox's IsEditable property is set to True).
It is possible to set the MaxLength property of the InputArea using the following approaches:
Using the TextBoxStyle property
As of Q2 2014 release RadComboBox provides TextBoxStyle property which makes it easy to customize the TextBox part of the control. Just create a custom Style with TargetType set to TextBox and set the MaxLength to the needed value as shown below:
If you are using Implicit Styles to style the controls, you would need to base that Style to the default TextBoxStyle of RadComboBox named ComboBoxTextBoxStyle.
Then, set the created Style as TextBoxStyle of RadComboBox:
Using the control Resources
By accessing the ComboBox resources it is possible to modify the Style of the TextBox in the control and set its MaxLength property.
The next code snippet shows how to set the MaxLength property of the TextBox in the control using its resources:
Using an Attached property
The idea in this case is to create a new Attached Property in a helper class.
In the OnMaxLengthChanged() 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 MaxLength property.
Finally set the property in XAML:
Note that you have to set the RadComboBox's IsEditable property to True.