UpdateValueEvent="LostFocus" still updates immediately on typing.

10 posts, 0 answers
  1. Lauren
    Lauren avatar
    4 posts
    Member since:
    Jan 2014

    Posted 09 Jan 2014 Link to this post

    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.

  2. Brian
    Brian avatar
    11 posts
    Member since:
    Sep 2012

    Posted 10 Jan 2014 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 14 Jan 2014 Link to this post

    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 >>
  5. Lauren
    Lauren avatar
    4 posts
    Member since:
    Jan 2014

    Posted 16 Jan 2014 Link to this post

    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
  6. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 21 Jan 2014 Link to this post

    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 >>
  7. Jan
    Jan avatar
    7 posts
    Member since:
    Aug 2010

    Posted 05 Jan 2015 in reply to Brian Link to this post

    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


     
  8. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 05 Jan 2015 Link to this post

    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.

     
  9. Jan
    Jan avatar
    7 posts
    Member since:
    Aug 2010

    Posted 05 Jan 2015 in reply to Kalin Link to this post

    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?
  10. Jan
    Jan avatar
    7 posts
    Member since:
    Aug 2010

    Posted 05 Jan 2015 in reply to Jan Link to this post

    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>
  11. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 05 Jan 2015 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready