UWP trigger command on keydown?

979 views Asked by At

I am trying to execute a command when the user presses a key:

   <TextBox Command="{Binding myCommand}" Height="200" Width="200" FontSize="20"></TextBox>

Now using UWP im not entirely sure how this is accomplished. In WPF we have keybindings but here? If possible without third party libraries. How would you guys solve this? I prefer not to reinvent the wheel and create my own command implementation that works for edge cases like these.

1

There are 1 answers

10
Isma On BEST ANSWER

Install the Behaviors NuGet if you don't have it and then:

<TextBox Height="200" Width="200" FontSize="20">  
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="KeyDown">
            <Core:InvokeCommandAction Command="{Binding myCommand}" />
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors> 
</TextBox>