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?