Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:05:54+00:00 2026-06-18T14:05:54+00:00

I have a DateTime property (say, DateVal) in my viewmodel class and a DatePicker

  • 0

I have a DateTime property (say, DateVal) in my viewmodel class and a DatePicker control in View.

    <DatePicker         Grid.Column="1"
                        Width="100"
                        Height="30"
                        SelectedDate="{Binding DateVal,ValidatesOnDataErrors=True}"/>

Problem is that, if the user deletes the date displayed in textbox of Datepicker control ,DateVal property is not changing its value. How can I track that the user has removed the Date displayed in datepicker textbox?
regards,
Anirban

The Date picker control looks like the following
Date picker before editing date picker text box
Now if the user just removes the date displayed in date picker text box, the control looks like the following
Date picker after editing date picker text box
At that point of time value of DateVal is same as before.
Only when the user clicks on the calender icon Date is assigned a value null.
How can I track the change at the same time when the user makes the text box empty ?

ViewModel Code

public DateTime? DateVal
    {
        get
        {
            return this.dateVal;
        }
        set
        {
            this.dateVal = value;
            this.OnPropertyChanged("DateVal");
        }
    }

xaml code

<DatePicker Name="datePickerDateVal"
                        Grid.Column="1"
                        Width="100"
                        Height="30"
                        SelectedDate="{Binding DateVal,ValidatesOnDataErrors=True}"
                        Text="{Binding DateVal,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"                          />

I want that the setter property of DateVal must be called when the user clears the Date Picker text box

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:05:56+00:00Added an answer on June 18, 2026 at 2:05 pm

    The sad news is that the textbox of the DatePicker is set to update its binding source only when it loses focus. The good-ish news is that you can hook into the process via the DatePicker‘s ControlTemplate:

    The XAML:

    <DatePicker SelectedDate="{Binding DateVal}" x:Name="__picker" />
    

    And the Code Behind:

    DateTime? _dateVal = DateTime.Today;
    
    public Nullable<DateTime> DateVal
    {
        get { return _dateVal; }
        set
        {
            if (_dateVal == value)
                return;
    
            _dateVal = value;
            OnPropertyChanged("DateVal");
        }
    }
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DatePickerTextBox pickerTextBox = __picker.Template.FindName("PART_TextBox", __picker) as DatePickerTextBox;
        if (pickerTextBox == null)
            return;
    
        pickerTextBox.TextChanged += new TextChangedEventHandler(pickerTextBox_TextChanged);
    }
    
    void pickerTextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        DatePickerTextBox tb = sender as DatePickerTextBox;
    
        if (tb == null)
            return;
    
        if (string.IsNullOrEmpty(tb.Text))
        {
            __picker.SelectedDate = null;
        }
    }
    

    I just fiddled around with it and my guess is that the reason you don’t get more frequent updates is the circular relation between the text and selected date properties. Making sure that we get updates for null DateTimes should be OK though.

    EDIT

    Updated the event handler to update the pickers SelectedDate property rather than the property in the view model. This way you can keep the hack entirely within the view while remaining viewmodel agnostic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say in my model I have public DateTime Date {get;set;} property. On the
Say I have a C# Nullable DateTime? property that needs to be consumed by
Requirement 1 Let's say I have some view model with two DateTime properties, Start
I have a datetime.datetime property var. I would like to know if it is
Currently I have a DateTime property for a model. I am using the telerik
I have objects that has a DateTime property, how can i query for the
I have a datetime column in db that I want to transform into a
Say I have an Employee class and one of its properties is of type
Say I have 2 kind: class Account(db.Model): name = db.StringProperty() create_time = db.DataTimeProperty() last_login
so lets say I have a simple class Final and I want to filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.