C# UWP disable phone keyboard for textbox or whole page

和自甴很熟 提交于 2019-12-12 05:08:10

问题


I have 2 TextBoxes. i made my own keyboard so the user uses my keyboard and its etrxa buttons. but when i tap on the textbox to type in it the phone keyboard on my phone emulator pops up. I tried the "PreventKeyboardDisplayOnProgrammaticFocus" but i read that it is only to disable it when the program itself chooses a textbox.

I read that the InputPane can help me disable it but i can't understand how to use it and can't find a way to do it anywhere else.

Can somebody help me i just want the keyboard disabled for specific textboxes or the whole page so when i tap on the textbox it won't pop up.

UPDATE: okay i managed after a lot of thought to do it for my app, i set both the textboxes xaml

    <TextBox IsReadOnly="True" />

so now the keyboard won't show up for that textbox since i "don't want to right" then my buttons depending on 2 flags that indicate wich TextBox is focused they will wright there. But still if someone knows how to disable the keyboard completely it could help, if i am not mistaken on android there is such a thing as disable keyboard for this textbox.


回答1:


You can use the TextBox.PreventKeyboardDisplayOnProgrammaticFocus property but you also need to change the focus of your Textbox to Programmatic.

A simple example is:

<TextBox x:Name="myTextBox" PreventKeyboardDisplayOnProgrammaticFocus="True"/>

public MainPage()
{
    this.InitializeComponent();
    timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromMilliseconds(500);
    timer.Tick += delegate
    {
        try
        {
            myTextBox.Focus(FocusState.Programmatic);
            timer.Stop();
        }
        catch { }
    };
}


来源:https://stackoverflow.com/questions/35774055/c-sharp-uwp-disable-phone-keyboard-for-textbox-or-whole-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!