When you declare RadzenTextBox with two way binding on property's object member (SelectedAcceptance.Number) as follow:
@inherits AcceptanceViewModel
@using Radzen
<RadzenTemplateForm TItem="IAcceptanceData"
Data="@this">
<FluentValidationValidator @ref="Validator" />
<RadzenTextBox @bind-Value=@SelectedAcceptance.Number />
<BarcodeComponent
Scanned="OnBarcodeScanned"
Changed="OnBarcodeChanged"
Disabled="@IsLoading" />
<RadzenTemplateForm>
Then this part of code will subscribe each time when parameters set
public class FormComponent<T> : RadzenComponent, IRadzenFormComponent
{
....
public override Task SetParametersAsync(ParameterView parameters)
{
var result = base.SetParametersAsync(parameters);
if (EditContext != null && ValueExpression != null && FieldIdentifier.Model != EditContext.Model)
{
FieldIdentifier = FieldIdentifier.Create(ValueExpression);
EditContext.OnValidationStateChanged += ValidationStateChanged;
}
return result;
}
Look at if block:
- EditContext is not null (I use RadzenTemplateForm with FluentValidationValidator)
- ValueExpression is not null RadzenTextBox is two-way binded
- The problem is here
FieldIdentifier.Model - this is reference to type of property SelectedAcceptance
EditContext.Model - this is reference to type of 'this' AcceptanceViewModel class contains property SelectedAcceptance which type contains property Name which two-way binded on RadzenTextBox.
So 'if' condition is true each time and each time when method SetParametersAsync is invoked (this happens each time when user enters data to BarcodeComponent due to blazor components lifecycle) EditContext.OnValidationStateChanged is subscribed again and again to handler ValidationStateChanged. After user enters data 100-150 times (100-150 scanned barcodes) it's significantly slow down app due to invoking StateHasChanged inside handler ValidationStateChanged 100-150 times on each data enetering
private void ValidationStateChanged(object sender, ValidationStateChangedEventArgs e)
{
StateHasChanged();
}
this could be fixed just do not bind to Property's member, but I think this is not obvious and just workaround