Blazor Tutorial C# – Part 8 – Blazor Cascading Values and Parameters

Coding Droplets

Blazor Tutorial C# – Part 8 is a tutorial video which explains everything about Blazor Cascading Values and Parameters.

Learn Blazor with Coding Droplets. Below is the Blazor Tutorial Playlist Link:

Blazor Cascading values and parameters provide a convenient way to flow data down a component hierarchy from an ancestor component to any number of descendent components. That means, the Cascading Value assigned from an ancestor component can be accessed from any of the child components.

Topics Covered in this Video:
– Cascading Values in Blazor – Usage of Blazor Cascading Value Component
– Cascading Parameters in Blazor – Usage of Blazor Cascading Parameter Attribute
– Blazor Cascading Parameters Example
– Blazor Cascading Values Example

Blazor Cascading Values and Parameters are a way to pass a value from a component to all of its descendants without having to use traditional component parameters.

Blazor comes with a special component called CascadingValue. This component allows whatever value is passed to it to be cascaded down its component tree to all of its descendants. The descendant components can then choose to collect the value by declaring a property of the same type, decorated with the [CascadingParameter] attribute.

If the cascaded values are of different type, this child component has to simply create a property of the same type and decorate with [CascadingParameter] attribute.

If multiple cascaded values of the same type are passed by the parent component to the child component, by default the cascaded value that is nearest to the child component in the hierarchy wins. To overcome this there is another way to access cascading values is by Name. A unique name should be provided for each of the values, these values will get cascaded to the descendant components by Name.
The child component can now decide which cascading value it wants by using the Name.

Blazor Cascading Value Component:
An ancestor component provides a cascading value using the Blazor Cascading Value component, which wraps a subtree of a component hierarchy and supplies a single value to all of the components within its subtree.

Blazor Cascading Parameter Attribute:
To make use of cascading values, descendent components declare cascading parameters using the [CascadingParameter] attribute. Cascading values are bound to cascading parameters by type or name. To cascade multiple values of the same type within the same subtree, provide a unique Name string to each CascadingValue component and their corresponding [CascadingParameter] attributes.

Video Chapters:
0:00 – Intro
3:15 – Basics of Blazor Cascading Values and Parameters
16:28 – Complex Objects as Cascading Values
23:56 – Dynamic Cascading Values