In wpf autocompletebox scroll bar does not move with up down key

1.2k Views Asked by At

In wpf the autocompletebox scroll bar does not move with the Up / Down key. When I select an item with Up / Down key, the scroll bar does not move with the selected item.

2

There are 2 best solutions below

0
On

This is my version of autocomplete, hope it helps :-

Download the WPF Toolkit and install it. Add a reference to System.Windows.Controls.Input.Toolkit in your project.

Add following code to your Page or window tag

xmlns:rm="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" 

Use it like following where you want to put the code

<rm:AutoCompleteBox Name="sellerText" Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" HorizontalAlignment="Left" Width="170" Margin="110,40,0,0" >
        <rm:AutoCompleteBox.SelectedItem>
            <Binding Source="{StaticResource insertTransaction}" Mode="TwoWay" UpdateSourceTrigger="Explicit" Path="Seller">
                <Binding.ValidationRules>
                    <ExceptionValidationRule/>
                </Binding.ValidationRules>
            </Binding>
        </rm:AutoCompleteBox.SelectedItem>
    </rm:AutoCompleteBox>
0
On

See my answer at https://stackoverflow.com/a/24241299/603268

Attach a SelectionChanged event and then, inside the handler:

private void AutoCompleteBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    AutoCompleteBox box = (AutoCompleteBox)sender;
    ListBox innerListBox = (ListBox) box.Template.FindName("Selector", box);
    innerListBox.ScrollIntoView(innerListBox.SelectedItem);
}