Invoking WPF command on IntegerUpDown (Extended WPF Toolkit)

404 Views Asked by At

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.

2

There are 2 best solutions below

0
On

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

0
On

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.