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

Calling BindinExpression.UpdateSource() doesn't update bound property

2 Answers 73 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 09 Mar 2011, 06:37 AM
I have a few RadNumericUpDown controls bound in TwoWay mode to properties. I have the following code that does get called when the KeyUp event occurs:
private void KeyUp(object sender, KeyEventArgs e)
{
    FrameworkElement fe = (FrameworkElement) sender;
    BindingExpression exp;
    if (fe is TextBox)
    {
        exp = fe.GetBindingExpression(TextBox.TextProperty);
    }
    else if (fe is RadNumericUpDown)
    {
        exp = fe.GetBindingExpression(RadRangeBase.ValueProperty);
    }
    else
    {
        throw new Exception("Invalid type");
    }
      
    exp.UpdateSource();
}

If I use this code on a TextBox the source is updated with the correct value but if I use a RadComboBox it does not update the source. What am I doing wrong?

What I'm trying to accomplish is to update all my bindings whenever a change is made to the RadNumericUpDown control without having to lose focus on the control. Pressing the up/down buttons in the control do update my bindings but typing numbers in the control do not until the contolr loses focus.

2 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 09 Mar 2011, 06:46 AM
I figured it out. I just needed to change the UpdateValueEvent like so
UpDown1.UpdateValueEvent = UpdateValueEvent.PropertyChanged;
Thanks for listening to me ramble :-)
0
sivakanth
Top achievements
Rank 1
answered on 12 Apr 2011, 01:51 PM
Hi Scott ,
              How to Update RadcomboBox value without losing Focus?
can u give me details..my mail id is s.sivakanth@gmail.com
Tags
NumericUpDown
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
sivakanth
Top achievements
Rank 1
Share this question
or