This is a migrated thread and some comments may be shown as answers.

MultiSelect should react to StateHasChanged()

1 Answer 371 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Veteran
Iron
Edward asked on 28 Oct 2020, 07:56 PM
I have a MultiSelect that is two-way bound to a List<Guid> selectedValues.  If selectedValues changes, I expect the MultiSelect to properly reflect the change once StateHasChanged() is called.  That is not the case, I have to do something like 

selectedValues = new List<Guid>(selectedValues) 

Apparently, creating a new reference triggers the notification and forces the component to redraw itself.  This seems very hackish and counterintuitive.  All components should check their state when StateHasChanged() is called and determine whether a UI update is necessary. 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 29 Oct 2020, 08:54 AM

Hello Edward,

In Blazor, the ParametersSet event of child components is called so they can react to changes in their parameters coming from their parent. The framework calls this event:

  • when a primitive (value) type parameter gets a new value - this is the common case for strings and numbers
  • when the reference to an object type parameter changes - this includes models and collections - and so the MultiSelect Value falls here. For a collection reference to change, you should generally do a "new List<T>(oldCollection)"

Thus, this is not about StateHasChanged() - it does not provide a new hook to react to - it is about when and how the framework passes new parameter values to the child components.

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MultiSelect
Asked by
Edward
Top achievements
Rank 1
Veteran
Iron
Answers by
Marin Bratanov
Telerik team
Share this question
or