Skip to content

Proposal: Enable basic expressions and calculations in XAML #1630

@weitzhandler

Description

@weitzhandler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions