This is a migrated thread and some comments may be shown as answers.
UpdateValueEvent="LostFocus" still updates immediately on typing.
11 Answers 110 Views
This is a migrated thread and some comments may be shown as answers.
Lauren
Top achievements
Rank 1
Lauren asked on 10 Jan 2014, 12:30 AM
Hi,

My company is using a RadNumericUpDown control being bound via xml to a viewmodel double value. We don't want the viewmodel's value to change until the numeric control has lost focus, however I haven't found a way to do this. I tried using the UpdateValueEvent="LostFocus" property setting in the xaml, however I notice that the viewmodel's value is still changing every keystroke, as opposed to being changed only when the numeric control has finally lost focus.

When that didn't work, I also tried setting the Value={Binding vmvalue, Mode=TwoWay, UpdateSourceTrigger=LostFocus} but that seemed to cause it to never update.

Am I missing something? Example code below:

<Window x:Class="RadNumSandbox.MainWindow"
        xmlns:local="clr-namespace:RadNumSandbox"
        Title="MainWindow" Height="200" Width="200"
        >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadNumericUpDown x:Name="radbox" Grid.Row="0" Value="{Binding Val, Mode=TwoWay}" UpdateValueEvent="LostFocus" />
    </Grid>
</Window>

And the code behind:

using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
 
namespace RadNumSandbox
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.DataContext = this;
            InitializeComponent();
        }
 
        private double val = 1.1;
        public double Val
        {
            get { return val; }
            set
            {
                if (value != val)
                {
                    val = value;
                    RaisePropertyChanged( "Val" );
                    Debug.Print( string.Format( "Val = {0}", val ) );
                }
            }
        }
 
        #region INotifyPropertyChanged Members
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        #endregion
 
        #region Methods
 
        private void RaisePropertyChanged( string propertyName )
        {
            // take a copy to prevent thread issues
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler( this, new PropertyChangedEventArgs( propertyName ) );
            }
        }
        #endregion
    }
}

When I run this code in the debugger, if I type in 1.23<Enter> I will see this output:

Val = 1
Val = 1.2
Val = 1.23

This shows the bound value is being changed before the control has lost focus.

11 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 10 Jan 2014, 08:46 PM
Lauren,

Did you figure this issue out? We are having the same problem.

When 'UpdateValueEvent' is set to 'LostFocus', my finding is that it's a character behind. If we try to enter 456, when you enter the 4, it does nothing. When you enter the 5, 'ValueChanged' event is triggered with new value of 4. When you enter the 6, 'ValueChanged' event is triggered with the new value of 45. And then when it loses focus, 'ValueChanged' is triggered with a new value of 456.

When we set 'UpdateValueEvent' is set to 'PropertyChanged', every keystroke triggers the 'ValueChanged' event (as you'd expect).

Just wanted to chime in on my findings. Any help would be appreciated.
0
Vladi
Telerik team
answered on 14 Jan 2014, 01:37 PM
Hi,

We tested the described scenario and it seems there is an issue regarding the UpdateValueEvent property of the RadNumericUpDown control. We will research the issue further and provide a fix for it in on of our future versions of the control.

In order to achieve the desire behavior you can simply set the UpdateSourceTrigger in the binding for the Value property to LostFocus. The next code snippet shows the described approach:
<telerik:RadNumericUpDown Value="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>

Hope this is helpful.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Lauren
Top achievements
Rank 1
answered on 16 Jan 2014, 10:54 PM
Valdi,

Thanks for your response. While your solution works in many situations, I unfortunately haven't found a way to make it work in one of my particular cases. I'm using the RadNumericUpDown control in a DataTemplate used for certain properties with the RadPropertyGrid control. Since in that control doesn't use typical binding (instead I have to use the AutoBindBehavior.UpdateBindingOnElelementLoaded attached behavior) I don't have the ability to set the binding parameters, such as UpdateSourceTrigger.

Any suggestions on how I might be able to manage in that case?

Thanks!
- Lauren
0
Yoan
Telerik team
answered on 21 Jan 2014, 07:18 PM
Hello Lauren,

Generally, the idea behind the AutoBind attached behavior is to enable reusable data templates in the scope of RadPropertyGrid. You can check this help article for more information about PropertyGrid's AutoBind Attached Behavior. However, you can define a "regular" PropertyDefinition with a RadNumericUpDown control as its editor template. This can be observed in this help article.

I hope this helps.


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jan
Top achievements
Rank 1
answered on 05 Jan 2015, 08:09 AM
I can confirm that RadNumericUpdown is "one behind" when you exit the field with a Tab character. However, pressing Enter to close the editing gives the correct value. This is the code that I use. Hope this helps in debugging. Meanwhile, as a workaround, you can tell users to ensure that they use the Enter key to commit changes (it's not a bug, it's a feature...)

01.<TelerikGridView:RadGridView x:Name="data" DataLoadMode="Synchronous" SelectionUnit="FullRow"  EnableRowVirtualization="False"
02.                                    EnableColumnVirtualization="False" AutoGenerateColumns="False" IsReadOnly="False" SelectionMode="Extended"
03.                                    IsSynchronizedWithCurrentItem="False"
04.                                     EditTriggers="CellClick" >
05.    <TelerikGridView:RadGridView.Columns>                                   
06.        <TelerikGridView:GridViewDataColumn DataMemberBinding="{Binding Length}" UniqueName="Length" >
07.            <TelerikGridView:GridViewDataColumn.CellEditTemplate>
08.                <DataTemplate>
09.                    <telerik:RadNumericUpDown Value="{Binding Length, Mode=TwoWay}" />
10.                </DataTemplate>
11.            </TelerikGridView:GridViewDataColumn.CellEditTemplate>
12.        </TelerikGridView:GridViewDataColumn>  
13.    </TelerikGridView:RadGridView.Columns>
14.</TelerikGridView:RadGridView


 
0
Kalin
Telerik team
answered on 05 Jan 2015, 09:19 AM
Hi Jan,

I tested the explained with the latest version of the controls and the bound property of the NumericUpDown control was updated correctly when the column is tabbed out. However what I can suggest you would be to  set the UpdateValueEvent of the control to PropertyChanged - this way the property will be updated on each key press.

Hope this helps.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jan
Top achievements
Rank 1
answered on 05 Jan 2015, 10:03 AM
Wasted hours on this. Found this: http://www.telerik.com/forums/issues-with-gridviewdatacolumn-celledittemplate
which also points to UpdateValueEvent. Tried changing UpdateValueEvent to LostFocus. Not working. Am using version 2013.3.1016.40. Would updating help?
0
Jan
Top achievements
Rank 1
answered on 05 Jan 2015, 10:19 AM
It works now! Working example (some unimportant properties omitted from production code):
01.<TelerikGridView:RadGridView x:Name="data"  
02.   DataLoadMode="Synchronous"
03.   ShowGroupPanel="False"
04.   ShowColumnFooters="False"
05.   ShowColumnHeaders="True"
06.   EnableRowVirtualization="False"
07.   EnableColumnVirtualization="False"
08.   AutoGenerateColumns="False"
09.   IsReadOnly="False"
10.   EditTriggers="CellClick"
11.   ActionOnLostFocus="CommitEdit" >  
12.   <TelerikGridView:RadGridView.Columns>
13. <TelerikGridView:GridViewDataColumn
14.  DataMemberBinding="{Binding Length}"
15.  UniqueName="Length"  >
16.  <TelerikGridView:GridViewDataColumn.CellEditTemplate>
17.   <DataTemplate>
18.    <telerik:RadNumericUpDown
19.     Value="{Binding Length, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                                                                 
20.     UpdateValueEvent="PropertyChanged" />
21.   </DataTemplate>
22.  </TelerikGridView:GridViewDataColumn.CellEditTemplate>
23. </TelerikGridView:GridViewDataColumn>                             
24.</TelerikGridView:RadGridView>
0
Kalin
Telerik team
answered on 05 Jan 2015, 03:31 PM
Hi Jan,

I'm glad you have managed to get it working as required. If you have any other questions, let us know.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Prashanth
Top achievements
Rank 1
answered on 07 Mar 2018, 01:46 PM

Set the Maximum value to 365. But when I type value above 365, eg: 366, it allows me to key (key_press event )in values 366 and it changes back to max value (365) only if I leave the control. What I need is, the user should not be allowed to key in values more than 365(only less than this number should allow).
Please suggest me if any approach.

0
Kalin
Telerik team
answered on 12 Mar 2018, 11:38 AM
Hello Prashanth,

You could implement data validation as demonstrated in this example (the link is for Silverlight, however the approach is the same for WPF) and set the UpdateValueEvent to PropertyChaged. This way you would be able to notify the user on each key stroke if the value is currently invalid.

Hope this will help you to achieve the desired.

Regards,
Kalin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Asked by
Lauren
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Vladi
Telerik team
Lauren
Top achievements
Rank 1
Yoan
Telerik team
Jan
Top achievements
Rank 1
Kalin
Telerik team
Prashanth
Top achievements
Rank 1
Share this question
or