Cursor Focus on Textbox in WPF/C#

前端 未结 8 1038
星月不相逢
星月不相逢 2020-12-23 22:14

I am currently in the process of creating a Onscreen keyboard. I am handling the button click using routedcommands. The issue is that when i click on the button in keyboard

8条回答
  •  臣服心动
    2020-12-23 22:57

    I had to use this to get my desired result

    FocusManager.SetFocusedElement(this, UserNameautoCompleteBox);
    
    Key key = Key.Enter;                    // Key to send
    var target = Keyboard.FocusedElement;    // Target element
    RoutedEvent routedEvent = Keyboard.KeyDownEvent; // Event to send
    
    target.RaiseEvent(
        new KeyEventArgs(
            Keyboard.PrimaryDevice,
            PresentationSource.FromVisual(UserNameautoCompleteBox),
            0,
            key) { RoutedEvent = routedEvent }
    );
    

提交回复
热议问题