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

0 Answers 27 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.
fabrizio
Top achievements
Rank 1
Iron
commented on 29 Aug 2025, 10:04 AM

Hello Martin,

I am experimenting with Parthiban your proposed solutions and check the consequent results.

I think it is useful to remark that we experience the issue only when the app is deployed on specific environments, while we correctly see SelectedDate and DisplayDate aligned when it comes to our debugging machines.

The environment in which we experience the issue (named "TEST") is a windows server hosting our application for "testing" purposes.

We tried to apply your first proposal:

1)
<local:NewDatePicker x:Name="MyDatePicker"
                     SelectedDate="{Binding MySelectedDate, Mode=TwoWay}"
                     DisplayDate="{Binding MySelectedDate}"/>       

with this solution - on the loading of the component - SelectedDate and DisplayDate are not aligned yet on TEST Environment.

We also tried to set "DisplayDate" in mode "TwoWay". When loading the component, this change causes a StackOverflowException that makes us think something is not correctly wired up on our/your side.

Also the solution 2) does not work as expected although the code is correctly executed. It looks like there is a time-gap in which every change to DisplayDate is not reflected or applied.

-----

What it is also worth mentioning to find a solution is that - when the issue occurs -

the SelectedDate is aligned with the value we actually specify through the binding (we see through the date box)

the DisplayDate (and SelectedDate on the calendar)  aligns instead with a value we bind instead as DisplayDateEnd (mode twoWay)

can this detail be of help for debugging the issue and find a workaround?

 

Thank you,

Fabrizio

Martin Ivanov
Telerik team
commented on 02 Sep 2025, 05:17 PM

Hi Fabrizio, thank you for the extra information. I've went through it, but I can't think of any additional suggestion on the topic. If you can share a runnable project showing the problem along with steps to reproduce it, I will check it on my side.

About the last statement in your last reply (about the DisplayDateEnd), note that if the DisplayDate is outside of the DisplayDateStart/End properties, the actual display date will be coerced so that it is between the display dates range. This won't directly affect the values of SelectedDate and DisplayDate though.

fabrizio
Top achievements
Rank 1
Iron
commented on 03 Sep 2025, 07:08 AM

Hello Martin,

unfortunately we can't provide a runnable project because the issue is strictly related to our environment of deployment. I doubt you would be able to reproduce it in your local.

As of now, my main question is: are you experiencing a StackOverflowException when binding "DisplayDate" in mode "Two Way" along with a "DispalyDateEnd" (OneWay) and a "SelectedDate" (TwoWay)?

 

Thank you for the information,

Fabrizio 

Stenly
Telerik team
commented on 08 Sep 2025, 01:16 PM

Hello Fabrizio,

I modified the sample project that my colleague, Martin, provided to bind the DisplayDate property with Mode=TwoWay, the SelectedDate property with Mode=TwoWay, and the DisplayDateEnd property with Mode=OneWay, however, I was unable to reproduce a StackOverflowException on my end.

I atttached the test application, so, would it be possible to give it a try?

fabrizio
Top achievements
Rank 1
Iron
commented on 10 Sep 2025, 09:24 AM | edited

Hello Stenly,

thank you for your example.

I did a bunch of tests on our application focusing on the properties provided in your example.

In our case with

DisplayDate property with Mode=TwoWay, the SelectedDate property with Mode=TwoWay, and the DisplayDateEnd property with Mode=OneWay

Our local machine: crashes of StackOverflowException in "PropertyPathWorker.cs" line 379: "pi.SetValue(item, value, null);"

TEST env: crashes of StackOverflowException

.................................................

I think we are getting closer to understand what is going on in this way.

From a further investigation, it looks like DisplayDate in TwoWay mode sends the app in an endless loop.

If it may be helpful for you, we usually place two NewDatePicker objects in our screens (and related properties in ViewModel), one to select the FromDate and the other for the ToDate. DisplayDateEnd of the first picker is binded to ToDate, while DisplayDateStart of the first is binded to FromDate, usually both in "OneWay".


                                    <custom:NewDatePicker
                                        AutomationProperties.AutomationId="fromDate"
                                        Culture="en-GB"
                                        DateTimeWatermarkContent="Select Date"
                                        DisplayDate="{Binding FromDate, Mode=TwoWay}"
                                        DisplayDateEnd="{Binding ToDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                        IsEmptyValueAllowed="True"
                                        SelectableDateStart="1/1/1950"
                                        SelectedValue="{Binding FromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat='dd MM yyyy'}">




                                    <custom:NewDatePicker
                                        AutomationProperties.AutomationId="toDate"
                                        Culture="en-GB"
                                        DateTimeWatermarkContent="Select Date"
                                        DisplayDate="{Binding ToDate, Mode=TwoWay}"
                                        DisplayDateStart="{Binding FromDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                        IsEmptyValueAllowed="True"
                                        SelectedValue="{Binding ToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat='dd MM yyyy'}">

Are you able to replicate something similar with these details? 

fabrizio
Top achievements
Rank 1
Iron
commented on 10 Sep 2025, 10:12 AM | edited

Providing another hint from a different pespective:

 

On opening on the sceen, the dark blue mark (1st of Sept in the image) is actually correct and aligned with the "SelectedDate".

Although that, at the click the calendar opens on the month where the DisplayDateEnd is positioned (in this case 10th of Sept).

If changing "SelectedDate" after first opening, the calendar month follows the dark blue mark.

No answers yet. Maybe you can help?

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