2

Since Microsoft doesn't allow to replace the system's virtual keyboard, I've developed a custom virtual keyboard as a UserControl to be used inside my Windows Store App. My current problem is that the default virtual keyboard always pops up whenever a user taps a TextBox.

I've been searching for a solution to this problem since yesterday, but I couldn't solve it. My almost successful attempt was developing a TextBox with a transparent Canvas over it. When the user taps the Canvas, the focus is programatically transferred to the TextBox and my custom virtual keyboard is instantiated. However, if no physical keyboard is connected to the tablet, the system keyboard also pops up with this approach (over my custom keyboard).

The main reason why I want to use a TextBox is because that way I can preserve and use the already implemented caret function, but it is not mandatory.

Any input will be helpful, thanks.

1 Answer 1

0

There are a couple of things you could do:

There are events for when the keyboard shows up, check those and see if you can prevent it.

You could implement a custom TextBox that suppresses OnPointerPressed event so that the TextBox is never focused. There are a couple of other things you'll need to do (such as prevent tabbing into it giving focus by setting IsTabStop=false.

You could implement a custom TextBox from the ground up (that looks and acts like a TextBox).

I think the second option is the easiest and most interesting option to try.

Edit: You could also give your TextBox a DependencyProperty that you set the current Page to via bindings. In the TextBox's OnGotFocus event, set the visual state to "CustomFocus" (or whatever you call it), then call Page.Focus();

7
  • Thanks for your inputs Nate. Do you have any clue on how can I supress the OnFocused event? Thanks again. Oct 5, 2013 at 11:34
  • I tried the second option as you suggested, but I don't know how can I suppress the event. RoutedEventArgs was supposed to have a Handled property, but it doesn't! When I try to set it, it says the property doesn't exist. And just overriding isn't enough: protected override void OnGotFocus(RoutedEventArgs e) { } Oct 7, 2013 at 19:24
  • Sorry it took so long to get back to you. I've done some more research and it turns out that once the OnGotFocus event hits, it already has focus and it is too late. You need to intercept the OnPointerPressed event and set the Handled there. You can then create your own VisualState and transition to it (for things like doing Carat animations). Changing my answer to reflect this. Oct 7, 2013 at 20:35
  • You are right Nate: if the event is intercepted in OnPointerPressed the TextBox isn't focused and the soft keyboard doesn't pop up. However, since the TextBox doesn't have focus, the caret isn't displayed... I guess I'll try the other alternative you sugested: implementing a TextBox from the ground. How do you suggest I represent the caret? The only option I could think of is constantly displaying and hiding a character that looks like the caret. Oct 8, 2013 at 13:48
  • I believe that's how they do it actually. You can do it with an animation that changes the opacity of the caret. If you use keyframes, you can have it auto-reverse and loop indefinitely (while in the 'CustomFocused' state). Oct 8, 2013 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.