[Error] Scrolling in AutoCompleteBox

May 21, 2012 at 5:22 PM
Edited May 21, 2012 at 5:32 PM

[protected override void OnKeyDown(KeyEventArgs e)]

From:

if (IsDropDownOpen)
            {
                if (SelectionAdapter != null)
                {
                    SelectionAdapter.HandleKeyDown(e);
                    if (e.Handled)
                    {
                        return;
                    }
                }

                if (e.Key == Key.Escape)
                {
                    OnAdapterSelectionCanceled(this, new RoutedEventArgs());
                    e.Handled = true;
                }
            }

To:

if( IsDropDownOpen )
      {
        if( SelectionAdapter != null )
        {
          SelectionAdapter.HandleKeyDown( e );

          if( SelectionAdapter.SelectedItem != null )
          {
            var selector = GetTemplateChild( ElementSelector ) as ListBox;
            if( selector != null )
            {
              selector.ScrollIntoView( SelectionAdapter.SelectedItem );
            }
          }

          if( e.Handled )
          {
            return;
          }
        }

        if( e.Key == Key.Escape )
        {
          OnAdapterSelectionCanceled( this, new RoutedEventArgs() );
          e.Handled = true;
        }
      }