Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Can anybody help me....how can i focus textbox and other controls while pressing backspace key....
Posted

1 solution

On your window you should add the PreviewKeyUp event.
if the key is backspace, set handled to true.
Call RequestFocusChange()

XML
PreviewKeyUp=Window_PreviewKeyUp


C#
private void Window_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
   if (e.Key==System.Windows.Input.Key.Back)
    {
       e.Handled = true;
       RequestFocusChange(FocusNavigationDirection.Previous);
    }
}

private static bool RequestFocusChange(FocusNavigationDirection direction)
{
  var focused = Keyboard.FocusedElement as UIElement;
  if (focused != null) return focused.MoveFocus(new TraversalRequest(direction));
  return false;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900