This is a migrated thread and some comments may be shown as answers.

UpdateSource to NumericUpDown

2 Answers 90 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Cheau-Long
Top achievements
Rank 1
Cheau-Long asked on 13 Jun 2011, 06:13 PM
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 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 16 Jun 2011, 02:53 PM
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
0
Cheau-Long
Top achievements
Rank 1
answered on 16 Jun 2011, 09:23 PM
It worked! Thanks very much.
Tags
NumericUpDown
Asked by
Cheau-Long
Top achievements
Rank 1
Answers by
Pana
Telerik team
Cheau-Long
Top achievements
Rank 1
Share this question
or