Two-way binding and background update does not re-render component
Hello,

I have a blazor server-side project, where i have a custom component, that uses a viewmodel to bind to SfSwitch.
If i change the viewmodel by clicking on a button, everything works fine.
But if i change the viewmodel by something more "background", like a grpc push message, then the SfSwitch is not re-rendered.
I have to trigger StateHasChanged() myself.
Is it expected behaviour, or do i have an error in my code ?
Thanks in advance.
best regards.
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
MK
Mohan Kumar Ramasamy
Syncfusion Team
December 30, 2020 10:19 AM UTC
Hi Gelai,
We have checked your reported query. We are unable to reproduce the reported issue in our end. For your reference we have prepared a sample based on this. Please refer below link and code snippets.
|
@using Syncfusion.Blazor.Buttons
<h4> IsOn: @ViewModel.IsOn </h4>
<br />
<SfSwitch @bind-Checked="@ViewModel.IsOn" TChecked="bool"></SfSwitch>
<br /><br />
<SfButton Content="Change" @onclick="Change"></SfButton>
@code {
public LightViewModel ViewModel { get; set; }
protected override Task OnInitializedAsync()
{
ViewModel = new LightViewModel();
return base.OnInitializedAsync();
}
private void Change()
{
ViewModel.IsOn = !ViewModel.IsOn;
}
public class LightViewModel
{
public bool IsOn { get; set; } = false;
}
}
|
If you are still facing the issue, kindly share the below details.
- If possible, try to reproduce the reported issue in sample or share the issue reproducible sample
2. Please share us the full code snippets
Please provide the above requested information, based on that we will check and provide you a better solution quickly.
Regards,
Mohan kumar R
GE
Gelai
December 30, 2020 10:31 PM UTC
Hello,
You've tried to reproduce with the scenario i said works ;)
If you change the viewmodel by clicking a button, it works just fine.
But if you change the viewmodel by some "background" means, it doesn't work without calling StateHasChanged.
In my case, i update the viewmodel when i receive a grpc push message. I'll try to reproduce with a background thread or something like that and send it to you.
MK
Mohan Kumar Ramasamy
Syncfusion Team
January 12, 2021 12:56 PM UTC
Hi Gelai,
We have checked your reported query. We are unable to reproduce the reported issue in our end. We have prepared a sample based on this. In this sample we have load data in button click then change the Switch component state, its working properly. If you have change Switch Component state in viewmodel, use StateHasChanged() method. Please refer below sample link.
Please let us know, if you need any further assistance.
Regards,
Mohan kumar
Marked as answer
SIGN IN To post a reply.