locked
Enter for Button Clicked Event is joking me around

    Question

  • Okay!

    Help!!

    I need to see if there is a straight answer to this, and if a newbie like me might be able to absorb it bye reading someone SIMPLE answer over and over again, until it is clear for life!

    I have a Button and 2 textboxes. When pressing button, a Try reads 2 doubles from the textboxes - performs a calculation - and return the correct answer back as a double - to a textblock. Its beutiful. But......

    As a Universal app, I would also like to fire the same "button click event" bye pressing ENTER on the touchscreen keyboard.

    Have seen examples like:

    private

    voidInputWeight_KeyDown(objectsender, KeyRoutedEventArgse)

    {

    if(e.Key == Windows.System.VirtualKey.Enter)

         {

             (do something)

         }

    }

    But it stops here for me - what is the command I should replace "(do something)" with - so that my already working click_event, above in my code, on this same page gets activated bye Enter being pressed.

    How freaking hard/easy is this....?!?!


    Regards, Kato.

    Sunday, June 08, 2014 9:20 PM

Answers

  • Hi Kato,

    The best way to handle this is to set up your Button to fire an ICommand rather than to do its handling in the Button.Click event. You can then also call the same ICommand from elsewhere (such as from your KeyDown handler).

    The non-basic template apps provide a RelayCommand class which makes building ICommands quite easy. Take a look at how the BackButton binds to the NavigationHelper.GoBackCommand for an example.

    --Rob

    Monday, June 09, 2014 4:23 AM
    Owner

All replies

  • Hi Kato,

    The best way to handle this is to set up your Button to fire an ICommand rather than to do its handling in the Button.Click event. You can then also call the same ICommand from elsewhere (such as from your KeyDown handler).

    The non-basic template apps provide a RelayCommand class which makes building ICommands quite easy. Take a look at how the BackButton binds to the NavigationHelper.GoBackCommand for an example.

    --Rob

    Monday, June 09, 2014 4:23 AM
    Owner
  • Cheers Rob,

    I will follow up with a working example as I get to it.

    And thanks so much for your time and feedback on this.

     


    Regards, Kato.

    Monday, June 09, 2014 10:48 AM