XAML / C#在Windows Phone 8.1 Store App中点击AppBarButton时不要关闭键盘

时间:2015-08-23 10:58:10

标签: c# xaml windows-phone-8.1

当用户完成输入并点按AppBarButton时,我无需关闭键盘。我怎么能这样做?

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

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>

但是我怎么能设置键盘才能保持可见,除非用户点击硬件后退按钮或只是点击某处?

1 个答案:

答案 0 :(得分:0)

我不认为你可以“强迫”键盘继续使用,当键盘失去焦点时它会被解雇,你可以做的就是让应用程序设置焦点键盘

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