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

Trigger on FormatError

1 Answer 46 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Gergely
Top achievements
Rank 1
Gergely asked on 17 Nov 2010, 06:33 PM
Hi,

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.

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 23 Nov 2010, 10:18 AM
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 - http://www.telerik.com/help/wpf/raddatetimepicker-how-to-implement-custom-parsing.html.


Greetings,
George
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
DatePicker
Asked by
Gergely
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or