RadNumericUpDown does not fire propertychanged when empty

3 posts, 1 answers
  1. Michael
    Michael avatar
    4 posts
    Member since:
    Jan 2016

    Posted 02 Sep Link to this post

    Hi,

     

    I encountered an issue with the RadNumericUpDown control. I have defined the UpdateValueEvent to PropertyChanged, this works fine as long as I am entering valid numeric values. But in case that I just delete the whole text from the NumericUpDown control the value is not updated in my viewmodel because the setter for the binded value is not called. When I leave the RadNumericUpDown afterwards the setter is called correctly and the value in my viewmodel is set to null.

    This is my definition in XAML

    <telerik:RadNumericUpDown Value="{Binding DurationFrom, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    ValueFormat="Numeric" NumberDecimalDigits="0" ShowButtons="True"
                    Minimum="1" Maximum="{Binding DurationTo, Mode=OneWay, TargetNullValue=1.0}"
                    NullValue="" UpdateValueEvent="PropertyChanged" />

     

    Is this a known issue with the NumericUpDown control and is there any workaround for this?

    Regards,

    Micha

     

  2. Answer
    Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 07 Sep Link to this post

    Hello Michael,

    We are already aware of the observed by you issue. It has been logged in our Feedback portal and you could vote for the item and track its status on the following link:
    http://feedback.telerik.com/Project/143/Feedback/Details/185812-numericupdown-numericupdown-the-value-of-numericupdown-with-updatevalueevent-se

    Until the issue gets fixed what we could suggest you is to handle the PreviewKeyDown event  of the NumericUpDown and explicitly set the value in its handler when the Backspace key is pressed. I have attached a sample project to demonstrate the approach, note that I have used our EventToCommandBehavior in order to handle the event in the ViewModel. Please download the attachment and give it a try.

    If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    4 posts
    Member since:
    Jan 2016

    Posted 07 Sep Link to this post

    Thanks Nasko,

     

    I amended your example a bit and figured out the following solution which works fine for me, maybe it helps others too.

     

    private void NumericUpDownKeyUp(object sender, KeyEventArgs e)
            {
                if (e != null && sender != null && ((e as KeyEventArgs).Key == Key.Delete || (e as KeyEventArgs).Key == Key.Back))
                {
                    if (string.IsNullOrEmpty((sender as RadNumericUpDown).ContentText))
                        (sender as RadNumericUpDown).Value = null;
                }
            }

Back to Top