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: x:Bind should support calling another function within its parameter list #2407

Open
michael-hawker opened this issue May 7, 2020 · 1 comment
Labels
area-Binding area-XamlCompiler feature proposal New feature proposal needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) product-winui3 WinUI 3 issues team-Markup Issue for the Markup team

Comments

@michael-hawker
Copy link
Collaborator

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

@michael-hawker michael-hawker added the feature proposal New feature proposal label May 7, 2020
@msft-github-bot msft-github-bot added this to Freezer in Feature tracking May 7, 2020
@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 7, 2020
@ranjeshj ranjeshj added the team-Markup Issue for the Markup team label May 8, 2020
@marb2000 marb2000 self-assigned this Jul 13, 2020
@marb2000 marb2000 removed the needs-triage Issue needs to be triaged by the area owners label Jul 13, 2020
@michael-hawker
Copy link
Collaborator Author

Just hit this again trying to do some Graph work with binding Query Options, would have been nice to do this:

<wgt:QueryOption
          Name="endDateTime"
          Value="{x:Bind system:DateTimeOffset.Now.Date.ToUniversalTime().AddDays(3).ToString('o', global:CultureInfo.InvariantCulture)}"/>

Unfortunately, it's not possible without this issue, so I have to break it up into two separate properties which is a pain.

Also, x:Bind/compiler doesn't seem to find the ToUniversalTime or AddDays methods? That seems like another bug, where should I file that? i.e. just trying to {x:Bind system:DateTimeOffset.Now.Date.ToUniversalTime()} fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Binding area-XamlCompiler feature proposal New feature proposal needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) product-winui3 WinUI 3 issues team-Markup Issue for the Markup team
Projects
Development

No branches or pull requests

5 participants