Skip to content

Simpler way to declare two-way bound parameters in Blazor components #28690

Closed
@lindespang

Description

@lindespang

Is your feature request related to a problem? Please describe.

I find myself writing a lot of boilerplate code when doing two-way bindings in Blazor like below. (It adds up if you have multiple parameters..)

@code {
    [Parameter]
    public TValue Value { get; set; }

    [Parameter]
    public EventCallback<TValue> ValueChanged { get; set; }
}

I think it would be nice to introduce another attribute that would generate the same source by only declaring one property.

Describe the solution you'd like

I would like it to look something like below (attribute semantics up for discussion)

@code {
    [BindableParameter]
    public TValue Value { get; set; }
}

Which would generate exactly the same source as

@code {
    [Parameter]
    public TValue Value { get; set; }

    [Parameter]
    public EventCallback<TValue> ValueChanged { get; set; }
}

Additional context

If I haven't missed anything obvious here I think this is a very clean and non-intrusive solution. I always write my bindable properties like this and have not yet encountered any situation that breaks that rule. Therefor I think this added attribute makes sense.

Please give feedback on this and let me know if I should take a look at it or if you want to do it yourselves!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions