RadzenDatePicker strange behaviour with StateHasChanged called from Background Task

Run this code:
start the timer with button click
click on RadzenDatePicker calender button,
select a Date in the calender.
then try to select another date in another month
=> every time the timer triggers, RadzenDatePicker jumps back to the calendar month of the date selected as first
??????
Run this code:
start the timer with button click
click on RadzenDatePicker calender button,
select a Date in the calender.
then try to select another date in another month
=> every time the timer triggers, RadzenDatePicker jumps back to the calendar month of the date selected as first
??????

.rz-calendar { --rz-input-height: 28px; --rz-input-font-size: 10px; }
@Message
Date from Date to
Start Timer

@code {
String Message { get; set;} = String.Empty;
DateTime? value;
DateTime? value2;
private System.Threading.Timer? timer;
void StartTimer()
{
timer = new System.Threading.Timer(async (object? stateInfo) =>
{
await UpdateUi();
}, new System.Threading.AutoResetEvent(false), 500, 3000); // fire every 3000 milliseconds
Message = "Timer Started";
}
protected async Task UpdateUi()
{
await InvokeAsync(StateHasChanged);
Message = "Timer Triggered " + DateTime.Now.ToString();
}
}

Hi @grsgrs,

You can check the forum FAQ for tips how to format your code snippets.

What you see seems to happen only when the DatePicker popup is opened. In order to position it properly it is appended to the end of the <body> element. Asynchronous rendering (such as caused by a timer) resets the DatePicker state because of that. This can be verified by using inline calendars <RadzenDatePicker Inline="true" />.

Unfortunately there isn't a way to address this. If using inline calendars is not an option you may consider using a different component that contains the timer logic so calling StateHasChanged updates only that component without affecting the rest of the UI. You can pass the DateTime values from the DatePickers as parameters:

Start: <RadzenDatePicker @bind-Value="@value" />
End: <RadzenDatePicker @bind-Value="@value1" />

<AutoUpdateComponent Start="@value" End="@value1" />

HI korchev
Just for me to understand:
When a Date in the DatePicker ist selected and the calender window of Datepicker is reopened and navigated to another month. And then a StateHasChanged is invoked from the background, and the open calender window then navigates automatically back to the selected Date? And this should not be a bug? And this cannot be fixed? Wow

We have pushed a change that should fix this issue. It turned the problem wasn't what I initially thought.

Ho korchev
Very nice thanks, when can I expect the new version?

The fix is already released with the latest version of the Radzen.Blazor nuget package.