Restore a default date when InputBox is blank

3 posts, 1 answers
  1. Olena
    Olena avatar
    11 posts
    Member since:
    Feb 2011

    Posted 17 Nov 2011 Link to this post

    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. Answer
    Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 22 Nov 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Olena
    Olena avatar
    11 posts
    Member since:
    Feb 2011

    Posted 23 Nov 2011 Link to this post

    So the trix is to declare this property as nullable!!! Date.
    Thanks a lot for your assistance, Ivo.
    Best regards\ Olena
Back to Top