Skip to content

[Proposal] Add BindingBase support for Bind extension methods to simplify nested bindings #465

Description

@stephenquan

Feature name

Add BindingBase support for Bind extension methods to simplify nested bindings

Link to discussion

#416

Link to PR

#417

Progress tracker

  • Android Implementation
  • iOS Implementation
  • MacCatalyst Implementation
  • Windows Implementation
  • Tizen Implementation
  • Unit Tests
  • Samples
  • Documentation

Summary

This proposal adds a simple Bind overload that accepts a pre-constructed BindingBase, enabling concise, type-safe bindings to nested view model properties. By leveraging the existing BindingBase.Create(...) API, developers can avoid fragile string paths and the verbose manual handler registration required by current expression-based overloads, while preserving fluent Markup syntax. The implementation is minimal, additive, and requires only a single overload that forwards the supplied binding to SetBinding.

Motivation

Binding to nested properties is currently either fragile (string paths) or verbose (manual property change handlers). Since BindingBase.Create(...) already provides type-safe nested property tracking, adding a Bind overload that accepts a BindingBase enables a much simpler and more maintainable syntax while preserving the fluent Markup API.

Detailed Design

Introduce a new Bind overload that accepts a pre-constructed BindingBase instance:

public static partial class BindableObjectExtensions
{
    public static TBindable Bind<TBindable>(
        this TBindable bindable,
        BindableProperty targetProperty,
        BindingBase binding)
        where TBindable : BindableObject
    {
        bindable.SetBinding(targetProperty, binding);
        return bindable;
    }
}

This overload enables any binding created through existing MAUI APIs, such as BindingBase.Create(...), to be used with the fluent Markup syntax:

new Entry().Bind(Entry.TextProperty, BindingBase.Create(static (ViewModel vm) => vm.NestedObject.Text));

Usage Syntax

#### Simple Property Binding

#
new Label().Bind(Label.TextProperty, BindingBase.Create(static (ViewModel vm) => vm.Name));


#### Nested Property Binding


new Entry().Bind(Entry.TextProperty, BindingBase.Create(static (ViewModel vm) => vm.NestedObject.Text));

Drawbacks

The new overload introduces another Bind variation, slightly increasing the API surface area and the number of overloads developers must choose from.

Alternatives

Continue Using String Paths

new Entry().Bind(Entry.TextProperty, "NestedObject.Text");

Or continue using existing expression-based overloads

new Entry().Bind(
    Entry.TextProperty,
    getter: static (ViewModel vm) => vm.NestedObject.Text,
    handlers: ...);

Or use SetBinding directly

entry.SetBinding(Entry.TextProperty, BindingBase.Create(static (ViewModel vm) => vm.NestedObject.Text));

Unresolved Questions

    1. Should the new overload accept only BindingBase, or should it also support derived binding types through additional generic overloads?
    1. Are there any overload resolution ambiguities with existing Bind methods when a BindingBase instance is supplied?
    1. Should documentation and samples be updated to recommend BindingBase.Create(...) as the preferred approach for nested bindings?
    1. Are there scenarios where BindingBase.Create(...) does not provide equivalent behaviour to the current handler-based overloads, and if so, should those limitations be documented?
    1. Does the toolkit wish to continue investing in the custom handler-based binding model, or should BindingBase.Create(...) become the primary recommended mechanism for complex binding scenarios?

Metadata

Metadata

Assignees

No one assigned

    Labels

    newproposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions