【问题标题】:XAML/C# Do not close keyboard when hit AppBarButton in Windows Phone 8.1 Store AppXAML / C#在Windows Phone 8.1 Store App中点击AppBarButton时不关闭键盘
【发布时间】:2015-08-23 20:56:27
【问题描述】:

当用户完成输入并点击AppBarButton 时,我不需要关闭键盘。我该怎么做?

目前,我使用此代码,但它只是在 AppBarButton 上触发 Click 事件后重新设置焦点。这是一个糟糕的解决方案。

private async void SendMessage(object sender, RoutedEventArgs e)
{
    this.MessageBox.Focus(FocusState.Keyboard);
    //my stuff
}

我的 XAML 以备不时之需:

    <TextBox x:Name="MessageBox"
        Margin="0,10,10,10"
        HorizontalAlignment="Right"
        Width="340"
        PlaceholderText="write a message..."
        InputScope="Chat"
        AcceptsReturn="True"
        TextWrapping="Wrap" />
        <!-- -->
    <Page.BottomAppBar>
        <CommandBar >
            <AppBarButton x:Name="SendButton" 
                Label="Send"
                Icon="Send"
                IsEnabled="{Binding IsSendEnabled}"
                Visibility="{Binding IsSendVisible, Converter={StaticResource IsVisibleWhenDisabled}}"
                Click="SendMessage" />
        </CommandBar >
    </Page.BottomAppBar>

但是,除非用户点击硬件返回按钮或只是点击某处,否则我如何设置键盘保持可见?

【问题讨论】:

  • windows phone 软键盘只有在文本框有焦点时才能打开。当用户按下视图焦点上的任何其他按钮时,会离开文本框,操作系统会关闭软键盘。您使用的方法是唯一的解决方案(不好的)。为什么不禁用应用栏按钮?它将向用户传达他们不再可操作的正确消息。
  • 尝试使用 Skype。当您点击“发送”时,键盘不会关闭。

标签: c# xaml windows-phone-8.1


【解决方案1】:

我认为您不能“强制”键盘保持打开状态,当键盘失去焦点时,它会被固定为关闭,您可以做的就是让应用程序将焦点设置为键盘

https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.focus(v=vs.110).aspx

【讨论】:

    猜你喜欢
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多