0

I have a user control for a textbox. In the codebehind of the user control i have a function called "TextBoxText_PreviewMouseDown", which shows a onscreen keyboard:

private void TextBoxText_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
    TextBox textbox = sender as TextBox;
    US_Keyboard keyboardWindow = new US_Keyboard(textbox, Window.GetWindow(this));
    if (keyboardWindow.ShowDialog() == true)
        textbox.Text = keyboardWindow.InputSource.Text;
}

my problem is, that if the onscreenkeyboard is shown, it gets the focus and in order to this the cursor disapears in the textbox.

The onscreenkeyboard is self made wpf keyboard (US_Keyboard), with a xaml file for the keyboard ui and a codebehind file for the keyboard logic.

here is the constructor of the keyboard:

public US_Keyboard(TextBox owner, Window wndOwner)
    {
        InitializeComponent();
        MainWindow = wndOwner;
        this.Owner = wndOwner;
        this.DataContext = this;
        InputSource = owner;
        SetKeyboardSize();
        SetKeyboardPosition();
    }
  • Is `US_Keyboard` your window? Simple set focus after showing it: `textbox.Focus();` – Sinatr Aug 25 '17 at 07:46
  • this does not work –  Aug 25 '17 at 08:27
  • You tagged question with OSK. Perhaps there are more things going on upon returning from `ShowDialog`. But how can we know without seeing the code? Do you still have OSK on screen after that? Do you use OSK.exe or what is *onscreenkeyboard* in your understanding? Can you add some screenshots where the problem can be seen? – Sinatr Aug 25 '17 at 08:34
  • sorry for the vague wording, i updated my question –  Aug 25 '17 at 08:47
  • You haven't described the problem *clearly*: *"it gets the focus and in order to this the cursor disapears in the textbox"* - sure thing, `ShowDialog` will activate new window and give it focus as well as it will block `Owner`. What do you want to happen: 1) when window is closed, then focus goes back to `TextBox` 2) while window is opened, focus is in `TextBox` ? For (1) just set focus manually as in my first comment, for (2) - don't open window modal, use `Show()` to open it modeless. – Sinatr Aug 25 '17 at 09:39
  • i don't want the textbox to keep the focus, i just need that the blinking cursor doesn't dissapear –  Sep 04 '17 at 06:41

0 Answers0