0

I am using mvvm pattern and using integerupdown button in the WPF application.
To invoke command currently I am using ValueChanged trigger as following -

    <i:Interaction.Triggers>
         <i:EventTrigger EventName="ValueChanged">
               <i:InvokeCommandAction Command="{Binding PercentChangedCommand}" />
         </i:EventTrigger>
    </i:Interaction.Triggers>

This works perfectly fine when user changes value using mouse click on up or down arrow.
Problem is the moment user wants to type in textbox, the event get triggered for every character typed in. Instead I want to allow user to type in numbers and trigger command only on hitting Enter.

Please suggest.

AbSharp
  • 119
  • 2
  • 6
  • 20

2 Answers2

0

if ValueChanged is triggered on every KeyStroke then your Bindings UpdateSourceTrigger is likely set to default (ValueChanged). Start by setting it to LostFocus. Additionally catch the KeyDown-event with an EventTrigger and check if the key pressed was the Enter-Key. If its the enter-key then simply call your command.

Edit: if you need a reusable solution for Commit-On-Enter-scenarios have a look at this question.

Sancho Panza
  • 670
  • 4
  • 11
0

Found a property - UpdateValueOnEnterKey="True". This will not invoke value changed on every character change, but only on Enterkey press

AbSharp
  • 119
  • 2
  • 6
  • 20