how to use "enter" key to execute a button's task from textbox RRS feed

  • Question

  • private void OnKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key == keys.Return) { Button_Click(this, new RoutedEventArgs()); } } private void Button_Click(object sender, RoutedEventArgs e) { //............... }

    this is the code I'm trying to use to get a button to do it's functions after "enter" is pressed

    and this is the code in the XAML section

    <TextBox x:Name="answerInput" Width="280" HorizontalAlignment="Left" KeyDown="OnKeyDownHandler"/>
    <Button x:Name="inputButton" Content="Check" Click="Button_Click"/>

    if (e.Key == keys.Enter) - this is the line with errors; the underlined words "key" (generates error CS1061) and "keys" (generates error CS0103) are the problem

    windows universal app; c#;

    thanks in advance for any help.

    Sunday, July 24, 2016 10:50 AM