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

NumericUpDown strange behavior

Dec 7, 2010 at 3:10 PM


i'm not sure if this is the right place for my question.

I intend to use the toolkit on a project and edited one of my controls to use the toolkits NumericUpDown.

As soon as i put the control into a datatemplate the fixed point number binding seems to fail.

I enter F2 as the format string to get 2 decimal places. The binding seems to work  the first time and the value in the vm is accessed.

But only 0,00 is displayed. When i set the formatstring to F0 the value gets displayed normally but obviously without the decimal places.

I created an example project which contains nothing but a screen with one NumericUpDown directly put into a grid and another one displayed trough a datatemplate and a contentcontrol.

Both use the same bindings. The one embedded into the datatemplate shows the behavior mentioned above while the directly integrated one works as expected.

I would really appreciate some input on this matter.


Kind Regards

Dec 7, 2010 at 3:27 PM

What version are you using? Are you using the latest source?  I am suspecting it has something to do with the Bindings in the DataTemplate.  Check your Output window and check for any binding errors with the data template.  Could you provide your sample code?

Dec 8, 2010 at 7:20 AM


the binding works if i don't use the F2 format string and i don't get any errors on the output. Also the value is read from the vm correctly but not displayed.

The xaml:


<Window x:Class="WPFToolkit.Extended.Samples.MainWindow"
        Title="MainWindow" Height="350" Width="525" >
            <DataTemplate x:Key="Foo">
                <extToolkit:NumericUpDown VerticalAlignment="Center" HorizontalAlignment="Left" FormatString="F2" Increment="1" Minimum="0" Maximum="100" Value="{Binding Path=DemoValue, Mode=TwoWay}"/>
        <ContentControl ContentTemplate="{DynamicResource Foo}" Content="{Binding}"/>
The codebehind is empty except for the setting of the datacontext.
The vm:
class TestVM:INotifyPropertyChanged
        public TestVM()
            this.demoValue = 3.1;

        private double demoValue;

        public double DemoValue
            get { return this.demoValue; }
                this.demoValue = value;

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Method requirded by INotifyPropertyChanged.
        /// </summary>
        protected void OnPropertyChanged(string changedProperty)
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(changedProperty));
Dec 8, 2010 at 5:05 PM

Are you using v1.2?  I was able to duplicate this is the v1.2 code base, but not in the current code base.  Please download the current source code and compile.  Let me know if it works out for you.

Dec 9, 2010 at 10:15 AM

Thank you for your help so far.


I switched from the 1.2 release to the latest version and now i can embed the control into the template. But now there is another problem when the value to which is bound is not a double.

I get the following errors:

System.Windows.Data Error: 23 : Cannot convert '4' from type 'Double' to type 'System.Int16' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: Int16Converter kann nicht von System.Double konvertieren.
   bei System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   bei System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   bei System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   bei MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
System.Windows.Data Error: 7 : ConvertBack cannot convert value '4' (type 'Double'). BindingExpression:Path=DemoValue; DataItem='TestVM' (HashCode=16775347); target element is 'NumericUpDown' (Name=''); target property is 'Value' (type 'Object') NotSupportedException:'System.NotSupportedException: Int16Converter kann nicht von System.Double konvertieren.
   bei MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
   bei MS.Internal.Data.ObjectTargetConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)
   bei System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)'

I'm using a German windows XP and an us version of vs2010. As far as i could trace this, it seems to be an issue when the value dp of the inputbase class is set.




Dec 9, 2010 at 11:23 AM

I found the solution to my problem. I have to set the ValueType property of the control to the type i'm binding against.

It would be nice for the control to get this automatically.


Thanks again for your help.