Subject: RadDatePicker Calendar Popup Shows Today's Date Instead of SelectedDate in Test Environment

0 Answers 12 Views
DatePicker
Parthiban
Top achievements
Rank 1
Parthiban asked on 23 Jul 2025, 12:04 PM | edited on 24 Jul 2025, 09:13 AM

Product: Telerik UI for WPF

Control: RadDatePicker (custom inherited as NewDatePicker)

Target Framework: .NET Framework 4.7

 

Issue Summary:

W're facing an inconsistency in behavior with the RadDatePicker control between development and test environments.

  • We have a custom control NewDatePicker that inherits from RadDatePicker.
  • At runtime, we bind a SelectedDate value (e.g., Jan 23, 2025) to the control.
  • When the user clicks to open the calendar popup:
    •   In development, the calendar popup correctly opens to SelectedDate.
    •   In test, the calendar popup opens to today's date (July 2025) instead of the bound SelectedDate.

 

Steps to Reproduce:

  1. Use a RadDatePicker or inherited control.

        2. Set SelectedDate = DateTime.Now.AddMonths(-6) (e.g., Jan 23, 2025).

        3. Run the application and open the DatePicker calendar.

        4. Observe the calendar view:

  •  Dev: shows January 2025 (as expected).
  •  Test: jumps to current date (July 2025), even though SelectedDate is Jan 23.

What We Tried:

  • Manually calling this.DisplayDate = this.SelectedDate.Value; inside OnPreviewMouseDown.
  • Using Dispatcher.BeginInvoke(..., DispatcherPriority.Loaded) to defer the update.
  • Accessing and setting PART_Calendar.DisplayDate explicitly.
  • Ensured that SelectedDate has a valid value.
  • Tried handling Loaded, OnApplyTemplate, and custom SyncDisplayDate() method.
  • Everything works well in development — but not in the test environment.


    Questions:
    1. Is there a recommended approach to ensure the calendar opens to the correct month consistently in all environments?

Note: In Test environment First time click that time its show the current Date secound time I click that time it show the expected output. 

 

  • the below the calendar need to show the 23 jan 2025 but its show current date.

Martin Ivanov
Telerik team
commented on 25 Jul 2025, 09:29 AM

I've tested this, but it seems to work on my side. You can check the attached project and tell me if I am missing anything. Here is also a screenshot:

Also, you can share what is the difference between your development and test environments.

Parthiban
Top achievements
Rank 1
commented on 25 Jul 2025, 11:12 AM

Issue Summary:

We are not using RadDatePicker directly.

Instead, we created a custom control (FleDatePicker) that inherits from Telerik.Windows.Controls.RadDatePicker.

The goal is to enforce a centralized date format (dd MMM yyyy) application-wide through this control.

Issue:

When using this inherited control:

  • In development, the calendar popup shows the correct SelectedDate (e.g., Jan 23, 2025) when clicked.
  • In test, the popup shows today’s date (e.g., Jul 2025), even though SelectedDate is set to a past value like Jan 23, 2025.

This issue only occurs when using the inherited control, not when using RadDatePicker directly.

 

Code Used in Custom Control (NewDatePicker):


public NewDatePicker()

{

this.AddHandler(Mouse.PreviewMouseDownEvent, new MouseButtonEventHandler(this.OnPreviewMouseDown), true);

}


private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)

{

if (!this.IsDropDownOpen)

{

this.Dispatcher.BeginInvoke(

new Action(() =>

{

this.SyncDisplayDate();

}),

DispatcherPriority.Loaded);

}

}



private void SyncDisplayDate()

{

if (this.SelectedDate.HasValue)

{

this.DisplayDate = this.SelectedDate.Value;



var calendar = this.Template.FindName("PART_Calendar", this) as RadCalendar;

if (calendar != null)

{

calendar.DisplayDate = this.SelectedDate.Value;

calendar.SelectedDate = this.SelectedDate;

}

}

}

 

Observations:

  • SyncDisplayDate() correctly sets DisplayDate and updates the internal calendar (PART_Calendar).
  • The method works perfectly in development.
  • But in the test environment, even though SyncDisplayDate() is called and SelectedDate is valid, the popup still defaults to today's date.
  • We suspect some timing, template-loading, or calendar-popup rendering difference between environments.

What We Need Help With:

  1. Is there a more reliable way (or event) to ensure the popup opens to the correct SelectedDate in inherited controls?
  2. Could this be caused by a timing issue or internal control behavior that differs when inheriting RadDatePicker?
  3. Is it safe and supported to programmatically access PART_Calendar and manipulate its DisplayDate, or is there a better approach?


Extra Notes:

  • We are enforcing a uniform dd MMM yyyy format using this control — which is why we chose inheritance.
  • We're not modifying visual styles or templates.

 

Martin Ivanov
Telerik team
commented on 25 Jul 2025, 11:49 AM

I haven't implement the custom variant of RadDatePicker because of the following step: "1. Use a RadDatePicker or inherited control." from your previous reply. Anyway, I've added the custom control in my sample project, but still the control works properly. I also added the Office2016 theme. You can see the changes in the attachment in this reply.

I still don't understand what you mean by "test" environment. Can you tell me what is this in your context? This may give me an idea on what might happen.

As for your new questions:

  • (1) Setting the SelectedDate and DisplayDate properties of RadDatePicker are the way of applying those days to the internal calendar control. There is no more convenient or reliable approach to do that.

    <local:NewDatePicker x:Name="MyDatePicker"
                         SelectedDate="{Binding MySelectedDate, Mode=TwoWay}"
                         DisplayDate="{Binding MySelectedDate}"/>        
  • (2) Yes, it could be a timing issue, as such situations are not uncommon in WPF, but without recreating this I can't tell what exactly happens. A wild guess would be that the local setting in the C# code overrides the default bindings to SelectedDate and DisplayDate of RadCalendar because it has a higher priority. An idea that you can test is to use the SetCurrentValue method instead of the local value settings used originally.
    var calendar = this.Template.FindName("PART_Calendar", this) as RadCalendar;
    if (calendar != null)
    {
        calendar.SetCurrentValue(RadCalendar.SelectedDateProperty, SelectedDate);
    
        if (SelectedDate.HasValue)
        {
            calendar.SetCurrentValue(RadCalendar.DisplayDateProperty, SelectedDate.Value);
        }
    }

    Note that this synchronization should not be needed in the first place, because the RadCalendar SelectedDate and DisplayDate are bound to the same properties of the RadDatePicker.
  • (3) Setting properties of PART_Calendar probably won't break the control, but you may change some settings or break bindings which are expected by the parent RadDatePicker. My recommendation here would be to set the calendar properties if you really need that, but to properly test the control behavior afterwards.

No answers yet. Maybe you can help?

Tags
DatePicker
Asked by
Parthiban
Top achievements
Rank 1
Share this question
or