question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor: Expose ICascadingValueComponent or otherwise allow implementing of custom Cascading Value Providers

See original GitHub issue

Is your feature request related to a problem?

Using CascadingValue may be too verbose if multiple values are needed somewhere down the line (i.e. it involves nesting of CascadingValues). In addition the behavior of CascadingValue is not as flexible.

Describe the solution you’d like

Therefore it would be nice to be able to author custom components that could also act as Cascading Value Providers by implementing ICascadingValueComponent interface or something similar.

Additional context

One scenario where it could be useful are templates: applying a bunch of different parameters / properties to one or more components of a certain type within a given scope (container). For example, there may be a general purpose, highly customizable “button” component, however it may be that within a certain scope (container) only particular buttons need to be rendered, so it would be nice to provide defaults for various desired parameters / properties of the button component which will be automatically applied to all button component instances in the container.

If the container is a custom component itself (quite often the case), then it would be nice to have the ability to specify those parameters / properties - defaults for a particular type of child control (i.e. button in this example) within the markup for the container control itself.

Alternatively, razor markup could be extended with some kind of container-scoped template element that would provide full intellisense for any components and provide defaults for the values of parameters of a given component type within that container scope:

<Container>

//Version 1:
<Template For="ComponentA" Prop1="SomeValue" Prop2="SomeValue" />
//Version 2:
<ComponentA:Template  Prop1="SomeValue" Prop2="SomeValue" />


<ComponentA></ComponentA> //<- Prop1 and Prop2 values from the template will be applied to all instances of ComponentA within the Container unless overriden by inline values

</Container>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fitdevcommented, Jun 1, 2020

@mrpmorris That’s exactly the problem I have too. Glad somebody else came across the need for such a scenario!

2reactions
mrpmorriscommented, May 31, 2020

I too now need this.

I want to write a base component that can be inherited by a page, and I need that base component to set some cascading values. The problem is, there is no way in a page to wrap CascadingValue around @ChildContent, because a pages don’t have a @ChildContent they simply override BuildRenderTree instead.

So, without making ICascadingValueComponent public, there is currently no way to create a base page component that sets cascading parameters 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor cascading values and parameters
An ancestor component provides a cascading value using the Blazor framework's CascadingValue component, which wraps a subtree of a component ...
Read more >
CascadingParameter Value null in Window
Solution. The solution is to expose a CascadingParameter in the component that hosts the Window, and use a new CascadingValue for its contents....
Read more >
Understanding Cascading Values & Cascading Parameters
Blazor comes with a special component called CascadingValue . This component allows whatever value is passed to it to be cascaded down its ......
Read more >
Blazor CascadingParameter vs singleton ...
It is implemented as a cascading value instead of a singleton. Components down the tree, like menus, can easily use this value to...
Read more >
Blazor cascading values and parameters
Blazor CascadingValue Component​​ We can pass a value to this component. This value is then cascaded down its component tree to all of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found