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: Enable basic expressions and calculations in XAML #1630

Open
weitzhandler opened this issue Nov 18, 2019 · 4 comments
Open

Proposal: Enable basic expressions and calculations in XAML #1630

weitzhandler opened this issue Nov 18, 2019 · 4 comments
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team

Comments

@weitzhandler
Copy link
Contributor

weitzhandler commented Nov 18, 2019

Proposal: Enable basic expressions and calculations in XAML

Summary

I often want to bind to a value but need to make addition, subtraction, multiplication, division, negation, string concatenation or a different simple mathematical formula.

It would be great, that instead of creating and maintaining a gazillion converters, there should be a built-in set of syntax conventions, such as simple arithmetic functions, negation, and maybe other basic math stuff, like Pow etc.
More advanced 2nd phase features would be type casting and conversion, calling a convert/convert back function in any .NET type (for instance System.Convert). Maybe there should be a general purpose converter for common cases, such as string or int to double etc.

Rationale

Here are some examples (not suggesting the actual syntax here):

<NumericUpDown Value="{Binding SelectedIndex+1}"/>
<TextBlock IsEnabled="{Binding !IsBusy}" />

But there should also be away to maintain TwoWay bindings, somehow.
If you're considering this functionality, this feature should be discussed as well, the goal is to reduce verbosity so something like:

<Slider 
  Value="{Binding CurrentIndex, Convert={x:Expression +1}, ConvertBack={x:Expression -1}}" />

might be to verbose.

Scope

Capability Priority
This proposal will save developers from writing and maintaining many converters Should
@robloo
Copy link
Contributor

robloo commented Nov 18, 2019

The Avalonia project already has some of these (such as negation). It might be useful to study the syntax.

@jevansaks jevansaks added the team-Markup Issue for the Markup team label Nov 19, 2019
@JerryNixon
Copy link

And let !true equal Collapsed on Visibility properties, of course.

@weitzhandler
Copy link
Contributor Author

Exactly. And other common scenarios. General idea is reduce XAML hassle and verbosity. Thanks Jerry tha Nixon!

@danzil danzil removed the needs-triage Issue needs to be triaged by the area owners label Mar 18, 2020
@michael-hawker
Copy link
Collaborator

It'd also be great to be able to call another function within the parameters to a function call within x:Bind. I thought I had filed another issue on that explicitly, but I can't find it now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature proposal New feature proposal team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

10 participants