Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to handle a generic type param being changed when pattern matching is required for the child fragments that do the editing

$
0
0

I have the following Blazor component:

@using System.Linq.Expressions@typeparam T@switch(Value){    case bool boolValue:<InputCheckbox @bind-Value=boolValue @bind-Value:after=ChangeValue />        break;    case string stringValue:<InputText @bind-Value=stringValue @bind-Value:after=ChangeValue />        break;}@code {    [Parameter] public T Value { get; set; }    [Parameter] public EventCallback<T> ValueChanged { get; set; }    [Parameter] public Expression<Func<T>>? ValueExpression { get; set; } = default;    private async Task ChangeValue()    {        await ValueChanged.InvokeAsync(Value);    }}

I am not clear how to bind the updated boolValue in InputCheckbox or stringValue in InputText back to Value and how to effectively coerce a bool or string into T.

If there is a better pattern for templating an editor such as this, then I am all for it, but I am going to be doing additional things within this editor once I get the basics working.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>