c# - 在 WP 中点击控件时不要隐藏软键盘

标签 c# button windows-phone-8 cursor windows-phone-8.1

我的 Windows Phone 8.1 Store App 项目(不是 Silverlight)中有这段按钮代码:

private void CursorRightButton_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrWhiteSpace(QueryTextBox.Text)) return;
        QueryTextBox.Focus(FocusState.Keyboard); //also i tried FocusState.Pointer
        QueryTextBox.Select((TextBox.SelectionStart + 1) % (TextBox.Text.Length + 1), 0);
    }

如您所见,我试图以编程方式将光标在文本中向右移动,问题是它隐藏了软键盘,然后在点击按钮后再次显示它。点击此按钮时我需要打开键盘。

我尝试修改 sender 和 TextBox 对象的 Focus() 方法,但找不到任何可能的解决方案。

所以问题是,如何强制键盘在点击控件时不失去焦点/不隐藏?

最佳答案

在 Sajeetharans 的帮助下,我发现我需要将控件上的 IsTabStop 值设置为 false。然后键盘将留在那里。我在我的页面构造函数中这样做

public MainPage()
{
    InitializeComponent();
    CursorLeftButton.IsTabStop = false;
    CursorRightButton.IsTabStop = false;
}

和我的按钮方法

private void CursorRightButton_Click(object sender, RoutedEventArgs e)
{
    if (string.IsNullOrWhiteSpace(TextBox.Text)) return;
    TextBox.Select((TextBox.SelectionStart + 1) % (TextBox.Text.Length + 1), 0);
}

关于c# - 在 WP 中点击控件时不要隐藏软键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23628377/

相关文章:

c# - 针对 Web API 的 HttpClient 基本身份验证失败,而浏览器按预期工作

java - 为什么%运算符在C/C++中不能用于 float ,但在Java和C#中可以使用?

c# - 3.5 框架中的哪些方法具有类似 String.Format 的签名?

python - 在 Python tkinter 中使用按钮计数器

c# - PointerPressed 和 PointerReleased 事件不匹配

c# - 当数组似乎不可能时,我可以使用什么集合?数据是否需要不可变,我可以有一个位置吗?

jquery - 为什么回发时文本框的值变为空?

python - kivy:如何使图像像按钮一样工作

c# - 在 Windows Phone 应用程序的 Pivot 和 Panorama 之间混合

c# - WP8 : Dispatcher. BeginInvoke 不在 UI 线程上执行操作