MathConverter
allows you to do Math in XAML.
MathConverter
is a powerful Binding
converter that allows you to specify how to perform conversions directly in XAML, without needing to define a new IValueConverter
in C# for every single conversion.
It's as easy as 1-2-3.
1) Install the Nuget package.
2) Add a MathConverter
resource.
<Application.Resources>
<math:MathConverter x:Key="Math" />
</Application.Resources>
The math
namespace is defined as follows:
xmlns:math="http://hexinnovation.com/math"
3) Do Math. Now, you can use MathConverter
on any Binding
. Specify a ConverterParameter
to specify the rules of the conversion.
<Border CornerRadius="{Binding ActualHeight, ConverterParameter=x/2, Converter={StaticResource Math}}" />
Or, for conversions with multiple bindings.
<Border CornerRadius="{math:Convert 'Min(x,y)/2', x={Binding ActualHeight}, y={Binding ActualWidth}}" />
See the GitHub repository for documentation and examples.