我有一个页面,里面有一些文本框和一个按钮
当我按下时,Enter我希望按下此按钮。
您想将AcceptButton
表单上的属性设置为要在输入时按下的按钮。
同样,如果您想要逃脱的东西,那就是CancelButton
财产。
XAML
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox Height="30" Width="200" KeyDown="TextBox_KeyDown" />
<Button Content="Login" Click="btnLogin_Click" HorizontalAlignment="Center"/>
<TextBlock x:Name="tbStatus" HorizontalAlignment="Center"/>
</StackPanel>
C#
private void TextBox_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
DoLogin();
}
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
DoLogin();
}
private void DoLogin()
{
tbStatus.Text = "Login Done";
}
我找到了答案,你必须在最后一个文本框/或所有文本框上使用事件“Keypress”,在里面写:
if (e.key == virtualkey.enter)
{
// do submit functions
}