How to set keyboard Focus programmaticaly?

SyntaxEditor for WPF Forum

Posted 4 years ago by BERKANT ORAL
Version: 15.1.0621
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

I have a WPF application which uses Syntax Editor on demand. To achieve this, on some key event I create an instance of Syntax Editor and append it to children of a grid. Immediately I call editor.Focus() or editor.ActiveView.Focus(). In both scenarios the editor is getting focused but editor is not listening key strokes and caret is invisible.

How can I dynamically set keyboard focus to syntax editor and continue to edit without additional mouse clicks?

Thanks.

Comments (2)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

That should work fine but note that if you call Focus() on any WPF element before it's fully loaded in the UI, it won't properly accept focus.  Are you doing this after the UI is loaded?  If not, you could try doing a Dispatcher.BeginInvoke to move it into a Loaded priority.


Actipro Software Support

Posted 4 years ago by BERKANT ORAL
Avatar

Dispatcher Invoke solved my problem thanks.

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.