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.
Here are some examples:
<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.
| Capability | Priority |
| :---------- | :------- |
| This proposal will save developers from writing and maintaining many converters | Should |
The Avalonia project already has some of these (such as negation). It might be useful to study the syntax.
And let !true equal Collapsed on Visibility properties, of course.
Exactly. And other common scenarios. General idea is reduce XAML hassle and verbosity. Thanks Jerry tha Nixon!
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...
Most helpful comment
And let !true equal Collapsed on Visibility properties, of course.