问题
I'm porting a game to Windows Phone 8.1 using C++/CX with DirectX 11. I need to bring up the soft keyboard for some text input.
Under Windows phone 8, I used the code provided by Microsoft here:
How to handle keyboard input in a Direct3D app for Windows Phone 8
This worked well but none of this code is valid in Windows Phone 8.1 and I've been unable to find any updated information. How can I do this in 8.1? I need to show/hide the keyboard and listen for keyboard inputs. Popping up a dialog box with a text input element would also be acceptable.
回答1:
The easy ways:
(on phone, but not desktop) call InputPane.TryShow and TryHide to explicitly open the input pane out of context from an actual control. You can catch the input in the CoreWindow.CharacterReceived event.
(on either) use a Xaml TextBox on top of your DirectX surface via Xaml DirectX Interop. This has the advantage of being easy as the Xaml controls already implement the accessibility and IME interfaces needed for full text support. It has the disadvantage of being external to the DX scene so it can require some care to place it nicely.
I generally try to do the full interactive form in Xaml rather than trying to merge a single TextBox into a scene. Putting the controls in a Xaml popup like you mention should work nicely.
The hard way:
- Implement your own fully functional control by providing the UI Automation text patterns and Text Service Framework (TSF) interfaces. Internally this is what the Xaml text controls do so that they appear to the system as text. When the user sets the focus to a text control (that supports the text patterns) the keyboard will automatically open.
来源:https://stackoverflow.com/questions/30141259/bringing-up-the-soft-keyboard-in-a-windows-phone-8-1-direct3d-app