I have a popup with a TextBox
that the user should enter a ticket number into, and then when the user presses the enter key I want the ticket number to be passed to the ViewModel which will retrieve the ticket.
Here's the xaml for the TextBox
:
<TextBox x:Name="TicketNumber">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<i:InvokeCommandAction Command="{Binding OpenTicketCommand}"
CommandParameter="{Binding ElementName=TicketNumber,
Path=Text}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
The above works on any keypress, but I really only want it to happen when the enter key is pressed. How would I go about doing that?
EDIT: I am assuming it would have to be done programmatically (hence the title), but if not that's okay too.
You could use InputBindings - KeyBinding
as alternative approach.
Something like this:
<TextBox x:Name="TicketNumber">
<TextBox.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding OpenTicketCommand}"
CommandParameter="{Binding ElementName=TicketNumber,
Path=Text}"/>
</TextBox.InputBindings>
</TextBox>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With