This project has moved. For the latest updates, please go here.

DecimalUpDown ValueChanged when typing by keyboard

Apr 17, 2012 at 1: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.

Coordinator
Apr 17, 2012 at 2:17 PM

Hi,

 

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 7: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.

Coordinator
May 14, 2012 at 7: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"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="MainWindow" Height="350" Width="525">
   <Window.Resources>
      <ControlTemplate x:Key="newDecimalUpDownTemplate"
                       TargetType="Control">
         <xctk:ButtonSpinner x:Name="Spinner"
                        IsTabStop="False"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}"
                        ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}">
            <xctk:WatermarkTextBox x:Name="TextBox"
                              BorderThickness="0"
                              Background="Transparent"
                              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}}"
                              MinWidth="20"
                              AcceptsReturn="False"
                              Padding="0"
                              SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}"
                              TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}"
                              TextWrapping="NoWrap" 
                              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}}" />
         </xctk:ButtonSpinner>
         <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
               <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
         </ControlTemplate.Triggers>
      </ControlTemplate>
   </Window.Resources>

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

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