CommunityToolkit/Maui.Markup

[Proposal] Further enhance typed binding support by adding BindCommand

bijington opened this issue · 6 comments

Feature name

Further enhance typed binding support by adding BindCommand

Link to discussion

n/a

Progress tracker

Summary

The work carried out in #155 didn't bring full typed binding support up to par with the existing binding support. We want to add in the BindCommand implementation to match the old binding functionality.

Motivation

Quicker bindings means quicker apps.

Detailed Design

public static TBindable BindCommand<TBindable, TBindingContext, TSource>(
    this TBindable bindable,
    Func<TBindingContext, TSource> getter,
    TSource? source = null,
    string? parameterPath = Binding.SelfPath,
    object? parameterSource = null) where TBindable : BindableObject
{
    ...
}

Usage Syntax

new Button().BindCommand(static (ViewModel vm) => vm.SubmitCommand);

Drawbacks

No response

Alternatives

No response

Unresolved Questions

No response

Is it necessary to mark the expression method as static?

Does it bring any benefits as have seen in the Bind method as well?

@brminnick

static is a recommended because it gives a performance boost to anonymous methods: https://paulsebastian.codes/static-anonymous-functions-with-c-9-quick-overview

You don't have to use static anonymous methods, but it is recommended.

I approve ✅

I approve ✅

Reopening Proposal.

Only Proposals moved to the Closed Project Column and Completed Project Column can be closed.