如何在UWP移动应用程序中禁用TextBox的输入窗格?

时间:2017-07-16 02:52:33

标签: textbox uwp

有TextBox和自定义键盘。当TextBox必须获得焦点时,我需要禁用输入窗格。我为展示和焦点事件尝试了TryHide方法。

InputPane.GetForCurrentView().TryHide();

但这是一个非常糟糕的解决方案,因为当用户正在使用TextBox时,InputPane会闪烁。然后我发现有可能在文档中更改输入策略CoreText​Input​Pane​Display​Policy但是文档没有解释如何应用此策略。 使用TextBlock不适合我,因为我需要使用光标进行操作并选择文本。这个问题有一个很好的解决方案吗?

1 个答案:

答案 0 :(得分:4)

Microsoft已展示代码示例here

        // Create a CoreTextEditContext for our custom edit control.
        CoreTextServicesManager manager = CoreTextServicesManager.GetForCurrentView();
        _editContext = manager.CreateEditContext();

        // Get the Input Pane so we can programmatically hide and show it.
        _inputPane = InputPane.GetForCurrentView();

        // For demonstration purposes, this sample sets the Input Pane display policy to Manual
        // so that it can manually show the software keyboard when the control gains focus and
        // dismiss it when the control loses focus. If you leave the policy as Automatic, then
        // the system will hide and show the Input Pane for you. Note that on Desktop, you will
        // need to implement the UIA text pattern to get expected automatic behavior.
        _editContext.InputPaneDisplayPolicy = CoreTextInputPaneDisplayPolicy.Manual;
相关问题