Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Further enhance Bind typed binding support to provide IValueConverter support #179

Closed
8 tasks done
bijington opened this issue Feb 2, 2023 · 1 comment · Fixed by #183
Closed
8 tasks done
Assignees
Labels
approved documentation approved help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail

Comments

@bijington
Copy link
Contributor

bijington commented Feb 2, 2023

Feature name

Further enhance Bind typed binding support to provide IValueConverter support

Link to discussion

I haven't created one

Progress tracker

Summary

Currently the Bind extension method provides an override to pass in an IValueConverter implementation and this works great with all of the toolkits converters. The new typed bindings implementation does not provide this support. I propose that we fix that.

Motivation

Faster bindings!

Detailed Design

/// <summary>Bind to a specified property with inline conversion and conversion parameter</summary>
public static TBindable Bind<TBindable, TBindingContext, TSource, TParam, TDest>(
    this TBindable bindable,
    BindableProperty targetProperty,
    Func<TBindingContext, TSource> getter,
    (Func<TBindingContext, object?>, string)[] handlers,
    Action<TBindingContext, TSource>? setter = null,
    BindingMode mode = BindingMode.Default,
    IValueConverter converter = null,
    TParam? converterParameter = default,
    string? stringFormat = null,
    TBindingContext? source = default,
    TDest? targetNullValue = default,
    TDest? fallbackValue = default) where TBindable : BindableObject
{
    bindable.SetBinding(targetProperty, new TypedBinding<TBindingContext, TSource>(bindingContext => (getter(bindingContext), true), setter, handlers.Select(x => x.ToTuple()).ToArray())
    {
        Mode = mode,
        Converter = converter,
        ConverterParameter = converterParameter,
        StringFormat = stringFormat,
        Source = source,
        TargetNullValue = targetNullValue,
        FallbackValue = fallbackValue
    });

    return bindable;
}

Usage Syntax

new Label()
    .Bind(
    Label.TextProperty,
    static (ViewModel vm => vm.MyFavoriteColor,
    converter: new ColorToByteAlphaConverter())

Drawbacks

No response

Alternatives

No response

Unresolved Questions

No response

@bijington bijington added proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail new labels Feb 2, 2023
@ghost ghost added this to Proposal Submitted in New Feature Proposals Feb 2, 2023
@brminnick brminnick self-assigned this Feb 2, 2023
@brminnick brminnick moved this from Proposal Submitted to Proposal Approved in New Feature Proposals Feb 2, 2023
@ghost ghost added approved help wanted This proposal has been approved and is ready to be implemented pending documentation This feature requires documentation and removed new labels Feb 2, 2023
@brminnick brminnick moved this from Proposal Approved to Pull Request Approved (Pending Documentation) in New Feature Proposals Feb 14, 2023
@brminnick brminnick moved this from Pull Request Approved (Pending Documentation) to Documentation Approved in New Feature Proposals Feb 14, 2023
@ghost ghost added documentation approved and removed pending documentation This feature requires documentation labels Feb 14, 2023
@ghost ghost reopened this Feb 14, 2023
@ghost
Copy link

ghost commented Feb 14, 2023

Reopening Proposal.

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

@brminnick brminnick moved this from Documentation Approved to Completed in New Feature Proposals Feb 28, 2023
@ghost ghost closed this as completed Feb 28, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved documentation approved help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail
Projects
Development

Successfully merging a pull request may close this issue.

2 participants