Trigger on FormatError

2 posts, 0 answers
  1. Gergely
    Gergely avatar
    11 posts
    Member since:
    Oct 2010

    Posted 17 Nov 2010 Link to this post


    I would like to set a default error handling method for all of my DatePicker controls in my application. This "default error handling method" is to set the last valid value on focus lost, if the actual value cannot be parsed. This way, I would like to avoid mistyping problems.

    For example if the current value is "2010-11-17" and the user types "aaa", I would like to reset the value back to "2010-11-17" on focus lost instead of clearing the value of the control.

    My first idea was to set this behavior in App.xaml as part of the default style of DatePicker (by triggers). Is it possible to achieve my goal this way? Could someone please help me with an example on how to do this? If my idea is wrong, could somebody tell me how this task can be solved?
    (The application is using the MVVM pattern.)

    Thank you for the answer in advance,
                                                                 G. M.
  2. George
    George avatar
    1332 posts

    Posted 23 Nov 2010 Link to this post

    Hello Gergely,

    I would suggest you to add a custom parsing logic. You need to handle ParseDateTimeValue and add the following logic:

    private void dateTimePicker_ParseDateTimeValue(object sender, ParseDateTimeEventArgs args)
                if (!args.IsParsingSuccessful)
                    args.Result = args.PreviousValue;
                    args.IsParsingSuccessful = true;

    For more information, please refer to the following link -

    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top