This project has moved and is read-only. For the latest updates, please go here.

DecimalUpDown ValueChanged when typing by keyboard

Apr 17, 2012 at 2:27 PM

Hello! When i'm typing by keyboard in DecimalUpDown control the ValueChanged property doesn't work. This event works only when scrolling by mouse or pressing Up or Down Buttons. Please, fix this bug with ValueChanged event.

Apr 17, 2012 at 3:17 PM



The ValueChanged event is being raised when you enter values with the keyboard.  However, the event is raised once when the underlying TextBox lose its focus.  It is not raised on each key hit.  This is the default behavior of the control.


If you want a different behavior, you will have to redefine the ControlTemplate of the DecimalUpDown control and bind its Text property to the underlying TextBox.Text property with UpdateSourceTrigger set to "PropertyChanged".

May 12, 2012 at 8:19 AM

Can you show me how to redefine the ControlTemplate of the DecimalUpDown control and bind its Text property to the underlying TextBox.Text property with UpdateSourceTrigger set to "PropertyChanged". Unfortunally I haven't got time to learn how to make it. If you have ability to make it for me, I will be very pleased to you, and also i'll donate to your project.

May 14, 2012 at 8:23 PM

Here is the modified ControlTemplate for the DecimalUpDown control.  Basically, it is a copy & paste of the template that was located at "WPFToolkit.Extended \ NumericUpDown \ Themes \ Generic.xaml".  I only added "UpdateSourceTrigger=PropertyChanged" in the WatermarkTextBox.Text binding.

<Window x:Class="DecimalUpDownTemplate.MainWindow"
        Title="MainWindow" Height="350" Width="525">
      <ControlTemplate x:Key="newDecimalUpDownTemplate"
         <xctk:ButtonSpinner x:Name="Spinner"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}"
                        ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}">
            <xctk:WatermarkTextBox x:Name="TextBox"
                              ContextMenu="{TemplateBinding ContextMenu}"
                              FontFamily="{TemplateBinding FontFamily}" 
                              FontSize="{TemplateBinding FontSize}" 
                              FontStretch="{TemplateBinding FontStretch}"
                              FontStyle="{TemplateBinding FontStyle}" 
                              FontWeight="{TemplateBinding FontWeight}" 
                              Foreground="{TemplateBinding Foreground}" 
                              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                              IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
                              SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}"
                              TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}"
                              TabIndex="{TemplateBinding TabIndex}"
                              Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
                              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                              Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"
                              WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" />
            <Trigger Property="IsEnabled" Value="False">
               <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />

      <xctk:DecimalUpDown Template="{StaticResource newDecimalUpDownTemplate}" />

You may also apply this template on a DoubleUpDown or an IntegerUpDown control if you need them to behave the same way.