Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Combobox: Cursor out of bounds when tried to enter text with length > combobox width

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.

like image 619
user296623 Avatar asked Nov 06 '22 05:11

user296623


1 Answers

Use ScrollViewer for PART_ContentHost instead of border. For example:

<ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
    <ScrollViewer x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding  Background}" />
</ControlTemplate>
... 
<TextBox x:Name="PART_EditableTextBox" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}" 
...
like image 55
nicolas2008 Avatar answered Nov 10 '22 21:11

nicolas2008