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:
- 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.
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.
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:
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:
What We Need Help With:
Extra Notes:
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:
<local:NewDatePicker x:Name="MyDatePicker" SelectedDate="{Binding MySelectedDate, Mode=TwoWay}" DisplayDate="{Binding MySelectedDate}"/>
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.
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
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.
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
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?
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?
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.