【问题标题】:Do NOT hide soft keyboard while tapping controls in WP在 WP 中点击控件时不要隐藏软键盘
【发布时间】:2014-05-13 20:03:48
【问题描述】:

我的 Windows Phone 8.1 应用商店应用项目(不是 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() 方法,但找不到任何可能的解决方案。

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

【问题讨论】:

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


    【解决方案1】:

    我在 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);
    }
    

    【讨论】:

      【解决方案2】:

      将加载的事件添加到您的容器中,例如网格,

      private void Grid_Loaded(object sender, RoutedEventArgs e)
      {
          this.IsTabStop = true;
          set focus on the control , say a textblock
          Txtblock1.Focus();
      }
      

      How To Programmatically Dismiss the SIP (keyboard)

      【讨论】:

      • 在这些按钮上将 IsTabStop 属性设置为 false 就成功了!
      • @KarelĐrakenusPchal 如果对您有帮助,您可以将其标记为答案
      • 当然,我已经做到了。但是,我只想告诉您,在 Windows Phone 8.1 中,Focus() 方法定义为 little different.
      猜你喜欢
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 2011-03-30
      • 2015-08-10
      • 1970-01-01
      相关资源
      最近更新 更多