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

Restore a default date when InputBox is blank

2 Answers 26 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Olena
Top achievements
Rank 1
Olena asked on 17 Nov 2011, 11:33 AM
Hello Telerik
I need to restore (some) default date in InputBox after user has blanked input. I have solved this task by binding SelectedValue-property to an Date object, implementing PropertyChanged event of the INotifyPropertyChanged interface and adding a Handler for LostFocus event. This approach works but I wonder if there is a better and smarter solution(solutions).
Thanks in advance.
Best regards\ Olena.

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivo
Telerik team
answered on 22 Nov 2011, 01:57 PM
Hello Olena,

I do not think you need to add handler for the LostFocus event of RadDatePicker. This is how I managed to implement it:
private DateTime? selectedDate;
 
public DateTime? SelectedDate
{
    get
    {
        var value = this.selectedDate == null ? DateTime.Today : (DateTime)this.selectedDate;
        return value;
    }
    set
    {
        var val = value == null ? DateTime.Today : value;
        this.selectedDate = val;
        OnPropertyChanged("SelectedDate");
    }
}

Hope this helps.

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Olena
Top achievements
Rank 1
answered on 23 Nov 2011, 10:10 AM
So the trix is to declare this property as nullable!!! Date.
Thanks a lot for your assistance, Ivo.
Best regards\ Olena
Tags
DatePicker
Asked by
Olena
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Olena
Top achievements
Rank 1
Share this question
or