Skip to content

Proposal: x:Bind should support calling another function within its parameter list #2407

@michael-hawker

Description

@michael-hawker

Proposal: x:Bind functions should support calling another function within its parameter list

From comment here, Related #1630

Summary

It's difficult to do complex expressions in x:Bind to composite to UI triggers/converter replacement type scenarios from back-end model data.

Rationale

  • By allowing x:Bind to chain functions within parameters, we can perform other calculations that would normally need extra converter or trigger code to perform.
  • A developer would be able to keep logic in context where it's used rather than obscuring it in another class.
  • Would be more performant to compile the expression down in the one-line in the generated code vs. creating a whole bunch of new objects and lookups to perform at runtime.

Scope

Capability Priority
Able to call another local/static function within one or more parameter arguments to another local/static function within an x:Bind expression Must
Inner functions can also accept the same binding or constant expression parameters that x:Bind accepts today Must
No (practical) limit on the number of nested functions called Should
Able to continue a chain on to the function expression with other method calls e.g. {x:Bind myns:StaticClass.DoConversion(ViewModel.Data).ToString()} Should
Can also do the same in the bindback expression Should

Examples

    {x:Bind myns:StaticClass.DoConversion(ViewModel.Data).ToArrayHelper().ToString()}
    {x:Bind myns:Helpers.Compare(Data.ToString(), "SomeString", Comparison.Equal)}
    {x:Bind myns:Helpers.ToVisibility(LookupValue(MyData.SomeProperty))}
    {x:Bind MakeBrush(ReadTextColor(Data.HexStringColor))}
    {x:Bind myns:StaticClass.Food(myns:StaticClass.Bar(ViewModel))}

Open Questions

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions