I am working with editable combobox where text can be entered in the textbox area of WPF combobox. When the length of text entered is greater than the width of combobox, the cursor still shows outside the combobox and on the form but text is not shown. Is there anyway to restrict the cursor from not moving out of the combobox?
Thanks.
You could override the default style and set the
MaxLengthproperty on theTextBoxbeing used for content presentation (PART_EditableTextBox) and then reuse that style where needed.If you would prefer to do it in code you can check out this SO answer which will achieve the same behavior but not force you to create a style.
EDIT:
If you want this to be more dynamic you will have to measure the text. You could handle the
TextChangedevent and perform the measurement.