Blazor: Expose ICascadingValueComponent or otherwise allow implementing of custom Cascading Value Providers
See original GitHub issueIs 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 CascadingValue
s). 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:
- Created 4 years ago
- Reactions:3
- Comments:18 (2 by maintainers)
@mrpmorris That’s exactly the problem I have too. Glad somebody else came across the need for such a scenario!
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 😦