【问题标题】:c# windows 8 hide keyboard when a combobox is presentc# windows 8在组合框出现时隐藏键盘
【发布时间】:2015-01-27 05:37:50
【问题描述】:

我想对 Windows 8 应用程序隐藏虚拟键盘。我知道如果将焦点设置在按钮上,它将隐藏,但我的问题是,如果我这样做,那么文本框下方的组合框将被冻结并且无法打开。我的代码:

<Grid Tapped="Grid_Tapped">
<Grid.RowDefinitions>
    <RowDefinition Height="auto"></RowDefinition>
    <RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>  

<TextBox Margin="12,12,12,12"  Grid.Row="0" VerticalAlignment="Center"
                     Name="aksiografo_textbox"
                     Text="{Binding ChequeNumber, Mode=TwoWay}" />

<ComboBox
Name="BankListPicker"
Grid.Row="1"
Margin="12,12,12,12" 
SelectedItem="{Binding Bank, Mode=TwoWay}"                        
ItemTemplate="{StaticResource LiPickerTemplate}" />
</Grid

private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{            
    ok_button.Focus(Windows.UI.Xaml.FocusState.Pointer);
}

【问题讨论】:

  • 这是因为 ComboBox.Tapped 事件冒泡并且触发了 Grid.Tapped 事件。为 ComboBox 创建一个 Tapped 事件处理程序并设置 e.Handled = true 可以解决该问题,但不能解决键盘弹出问题。你这样解决不了,我觉得没有。

标签: c# combobox keyboard hide windows-8.1


【解决方案1】:

我解决了。问题确实是被窃听的事件。我创建了一个 boolean combotapped=false;

private void combo_tapped(object sender, TappedRoutedEventArgs e)
{
    combotapped = true;
}

private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
   if (combotapped == false)
   ok_button.Focus(Windows.UI.Xaml.FocusState.Pointer);

   combotapped = false;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    相关资源
    最近更新 更多