I've followed this question and it works well, but it takes away focus from my sending control.
What I'm trying to do is to create an entry box that works like an auto complete text box - a text box and a popup control that contains the list of matching items. I need to be able to take keys, such as Up,Down and route them to the popup control, and take the other keys and keep them on the text box.
switch (e.Key)
{
case Key.Down:
{
if (!popup.IsOpen)
{
openPopup();
}
else
{
PresentationSource source = PresentationSource.FromVisual( itemList );
if ( source == null ) return;
itemList.RaiseEvent(
new KeyEventArgs( Keyboard.PrimaryDevice, source, 0, e.Key )
{RoutedEvent = Keyboard.KeyDownEvent} );
}
break;
}
}
itemList above is the control that's pop'd up and focus gets transferred as soon as I call RaiseEvent.