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.