【发布时间】: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