0
votes

we use Mindfusion wpf keyboard in our project.

every time that a textbox got focused we open keyboard dialog for the user.

if its a regular textbox without any behavior everything works fine, but when we use this keyboard for textbox with "select all" behavior we can only enter one char, because it selects the text after keypress on the keyboard.

we checked and it's not a problem with the mindfusion keyboard because when we use it as user control it works. when we open this keyboard from thier application it works. and when we open windows keyboard it works.

i think it most be something with the dialog window.

we tried to set it as focusable=false and showactivated=false and it's not working.

we also tried to use focusmanger and win32.showunactivated

here is the behavior code:

public class SelectAllTextOnFocusBehavior : Behavior<TextBox>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.GotKeyboardFocus += AssociatedObjectGotKeyboardFocus;
        AssociatedObject.GotMouseCapture += AssociatedObjectGotMouseCapture;
        AssociatedObject.PreviewMouseLeftButtonDown += AssociatedObjectPreviewMouseLeftButtonDown;
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.GotKeyboardFocus -= AssociatedObjectGotKeyboardFocus;
        AssociatedObject.GotMouseCapture -= AssociatedObjectGotMouseCapture;
        AssociatedObject.PreviewMouseLeftButtonDown -= AssociatedObjectPreviewMouseLeftButtonDown;
    }

    private void AssociatedObjectGotKeyboardFocus(object sender,
        System.Windows.Input.KeyboardFocusChangedEventArgs e)
    {
        AssociatedObject.SelectAll();
        Console.WriteLine("AssociatedObjectGotKeyboardFocus");
    }

    private void AssociatedObjectGotMouseCapture(object sender,
        System.Windows.Input.MouseEventArgs e)
    {
        AssociatedObject.SelectAll();
        Console.WriteLine("AssociatedObjectGotMouseCapture");
    }

    private void AssociatedObjectPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (!AssociatedObject.IsKeyboardFocusWithin)
        {
            AssociatedObject.Focus();
            Console.WriteLine("AssociatedObjectPreviewMouseLeftButtonDown");

            e.Handled = true;
        }
    }
}

do you have any idea how to prevent it from losing keyboard focus?

1

1 Answers

1
votes

the solution is to open the window in another thread... we waste 12 hours in order to solve it..

        var thread = new Thread(() =>
        {
            fk = new FullKeyboard();
            fk.Show();
            App.Current.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
            System.Windows.Threading.Dispatcher.Run();
        });

        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();