protected override void OnKeyDown(KeyEventArgs e)
{
if(e == null)
{
throw new ArgumentNullException("e");
}
base.OnKeyDown(e);
if(e.Handled || !IsEnabled)
{
return;
}
// The drop down is open, pass along the key event arguments to the
// selection adapter. If it isn't handled by the adapter's logic,
// then we handle some simple navigation scenarios for controlling
// the drop down.
if(IsDropDownOpen)
{
if(SelectionAdapter != null)
{
SelectionAdapter.HandleKeyDown(e);
if(e.Handled)
{
return;
}
}
if(e.Key == Key.Escape)
{
OnAdapterSelectionCanceled(this, new RoutedEventArgs());
e.Handled = true;
}
}
else
{
// The drop down is not open, the Down key will toggle it open.
if(e.Key == Key.Down)
{
IsDropDownOpen = true;
e.Handled = true;
}
}
// Standard drop down navigation
switch(e.Key)
{
case Key.F4:
IsDropDownOpen = !IsDropDownOpen;
e.Handled = true;
break;
case Key.Enter:
OnAdapterSelectionComplete(this, new RoutedEventArgs());
e.Handled = true;
break;
}
}