UpdateSource to NumericUpDown

3 posts, 0 answers
  1. Cheau-Long
    Cheau-Long avatar
    27 posts
    Member since:
    Jan 2011

    Posted 13 Jun 2011 Link to this post

    Hi Telerik,

    When the RadNumericUpDown is in focus, I'd like to update the source in VM. I created a simple method to grab the focused element from the keyboard and update the source. The problem is the Keyboard.FocusedElement returned a type called PickerTextBox instead of RadNumericUpDown and thus the highlighted codes won't be fired. My question is how I can UpdateSource to NumericUpDown properly? The original problem is when the RadNumericUpDown is in focus and user saves the app, the RadNumericUpDown source won't be updated.

            private void UpdateFocusedTextBox()

            {

                //There is an issue when textbox is in focus, it won't update the source.

                //This workaround will try to find the currently focusedTextBox and update the source.

                object focusedTextBox = Keyboard.FocusedElement;

     

                if (focusedTextBox is RadNumericUpDown)

                {

                    RadNumericUpDown rad = focusedTextBox as RadNumericUpDown;

                    ((RadNumericUpDown)focusedTextBox).GetBindingExpression(RadNumericUpDown.ValueProperty).UpdateSource();

                }           

                else if(focusedTextBox is TextBox)

                    ((TextBox)focusedTextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource();        

            }

  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 16 Jun 2011 Link to this post

    Hello,

    This happens because in fact the PickerTextBox inside the RadNumericUpDown is focused. If you want to get the RadNumericUpDown that the PickerTextBox belongs to you can use the Telerik.Windows.Controls UIElement's extension method for ParentOfType<RadNumericUpDown>(). If the method returns a RadNumericUpDown then you can use it to get the value.

    All the best,
    Pana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Cheau-Long
    Cheau-Long avatar
    27 posts
    Member since:
    Jan 2011

    Posted 16 Jun 2011 Link to this post

    It worked! Thanks very much.
Back to Top