0

I have to write an app for a Raspberry Pi 2 and I'm using VS2015 Universal Windows app.

In my previous projects I have used the following code to bind key events:

<TextBox>
    <TextBox.InputBindings>
        <KeyBinding Command="{Binding LoginCommand}" Key="Enter" />
    </TextBox.InputBindings>
</TextBox

In WinRT there's no such thing as <TextBox.InputBindings>. What is the equivalent of WPF MVVM's TextBox.InputBindings in WinRT?

Sam
  • 85
  • 3
  • 16

1 Answers1

0

I think this is not available in WinRT.

https://msdn.microsoft.com/en-us/library/windows/apps/hh868161.aspx?f=255&MSPPError=-2147217396

Important Setting AutomationProperties.AcceleratorKey or AutomationProperties.AccessKey doesn't enable keyboard functionality. It only reports to the UI Automation framework what keys should be used, so that such information can be passed on to users via assistive technologies. The implementation for key handling still needs to be done in code, not XAML. You will still need to attach handlers for KeyDown or KeyUp events on the relevant control in order to actually implement the keyboard shortcut behavior in your app. Also, the underline text decoration for an access key is not provided automatically. You must explicitly underline the text for the specific key in your mnemonic as inline Underline formatting if you wish to show underlined text in the UI.

kirotab
  • 1,296
  • 1
  • 11
  • 18
  • Thanks for the answer @Kirotab, I had my doubts but now I'm certain. Is there a work around I can use to tell my VM that the enter key has been pressed ? Recently I came across this link : [link](http://stackoverflow.com/questions/4834227/invoke-command-when-enter-key-is-pressed-in-xaml) and the answer posted by @bitxwise was pretty usefull. Sadly I tried his method but the `FrameworkElement_KeyDown()` event is called twice for some reason when the enter key is pressed on a textbox in my case. – Sam Oct 29 '15 at 17:02
  • Thanks for sharing this, looks nice (unlike the solution that I did with code behind handling a while ago where I fired my command manually from the KeyDown handler (LoginBtn.Command.Execute(null)). As soon as I find some time I'll check it out. And for the multiple event's I had the same issue and I had to finish my task in a hurry so the quick workaround was to add additional flag that is raised when I start handling the button down and is released when I finish handling it. I'm not 100% sure what caused it but I was thinking that it's caused because of long press on the virtual keyboard. – kirotab Oct 29 '15 at 17:17