### Install MathConverter via Package Manager
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Commands to install the required NuGet packages for WPF or MAUI projects.
```powershell
PM> Install-Package MathConverter
PM> Install-Package MathConverter.Maui
```
--------------------------------
### Basic MathConverter Setup in XAML
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Add MathConverter to your resources and use it with a Binding by specifying a ConverterParameter expression.
```xaml
```
--------------------------------
### Perform Basic Math in Binding
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Examples of using MathConverter to perform arithmetic operations on binding values.
```xml
```
```xml
```
--------------------------------
### String Searching with StartsWith and Contains
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Check if a string starts with a specific prefix or contains a substring. The result can be used for conditional visibility.
```xaml
```
```xaml
```
--------------------------------
### Format Function Example
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Demonstrates the equivalence of interpolated strings and the Format function. The interpolated string $`Hello, {x}` is equivalent to Format('Hello, {0}', x).
```C#
Format('Hello, {0}', x)
```
--------------------------------
### Get Current Date and Time
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Retrieve the current date and time using the `Now()` function. The output can be formatted using string interpolation.
```xaml
```
--------------------------------
### Perform Single Binding Conversion
Source: https://github.com/hexinnovation/mathconverter/blob/main/Nuget README.md
Use MathConverter for single binding conversions by specifying the conversion logic in the ConverterParameter. This example divides the ActualHeight by 2.
```xaml
```
--------------------------------
### Specify Different Margins with MathConverter
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Use MathConverter with multiple values for types like Thickness by separating values with commas or semicolons in the ConverterParameter. This example sets different left/right and top/bottom margins.
```xaml
```
--------------------------------
### String Interpolation with ConverterParameter
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Use ConverterParameter with string interpolation for dynamic text formatting in bindings. The example shows how to format a string based on a bound property 'NumClicks'.
```XAML
```
--------------------------------
### MathConverter with Optional ConverterParameter
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
When ConverterParameter is omitted, MathConverter joins binding values with a comma. This example demonstrates creating different Thickness values from multiple bindings.
```xaml
```
```xaml
```
--------------------------------
### Get Type Information
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Retrieve the type of a given value using the `GetType` function. This is useful for runtime type checking or debugging.
```xaml
```
--------------------------------
### Interpolated Strings
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
Interpolated strings in MathConverter function similarly to C#, allowing dynamic string formatting. They must start and end with the same quote character.
```APIDOC
## Interpolated Strings
Interpolated strings work the same way as they do in C#. The same rules apply: a string must start and end with the same character.
### Example
```
$"'Coordinates: ({x:N2},{y:N2}).'"
$"The weather outside is {x}."
`` $`Progress: {x:P} complete` ``
```
> **Note:** An interpolated string is a wrapper around a call to the `Format` function, so `$'Hello, {x}'` is equivalent to `Format('Hello, {0}', x)`.
```
--------------------------------
### Use Convert MarkupExtension
Source: https://github.com/hexinnovation/mathconverter/blob/main/README.md
A more concise syntax for performing multi-binding calculations using the math:Convert extension.
```xml
CornerRadius="{math:Convert 'Min(x,y)/2', x={Binding ActualHeight}, y={Binding ActualWidth}}"
```
--------------------------------
### String Formatting with Format Function
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Format strings using placeholders and format specifiers. The `x` parameter represents the value to be formatted.
```xaml
```
--------------------------------
### Configure MathConverter Options
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Adjust caching behavior and unset value handling via XAML or C# properties.
```xaml
```
```csharp
// Clear cache programmatically
var math = (MathConverter)FindResource("Math");
math.ClearCache();
// Check cache setting
bool usesCaching = math.UseCache;
// Disable caching at runtime
math.UseCache = false;
```
--------------------------------
### Error Handling with TryCatch
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Execute expressions sequentially and return the result of the first one that does not throw an exception. Useful for handling potential division by zero or other errors.
```xaml
```
--------------------------------
### String Functions
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Functions for case conversion, searching, formatting, and joining strings.
```APIDOC
## String Functions
### Description
Provides utilities for manipulating strings within XAML bindings, including case conversion, pattern matching, and formatting.
### Functions
- **ToUpper(x)**: Converts string to uppercase.
- **ToLower(x)**: Converts string to lowercase.
- **StartsWith(x, pattern)**: Returns boolean if string starts with pattern.
- **Contains(x, pattern)**: Returns boolean if string contains pattern.
- **Format(format, x)**: Formats a string using standard .NET format strings.
- **Concat(x, separator, y)**: Concatenates multiple values with a separator.
- **Join(separator, ...args)**: Joins multiple arguments with a specified separator.
```
--------------------------------
### Create Custom MathConverter Functions in C#
Source: https://context7.com/hexinnovation/mathconverter/llms.txt
Inherit from base classes like OneArgFunction, OneDoubleFunction, TwoArgFunction, or ArbitraryArgFunction to define custom logic.
```csharp
// Custom function that takes one argument
using HexInnovation;
using System;
using System.Globalization;
public class GetWindowTitleFunction : OneArgFunction
{
public override object? Evaluate(CultureInfo cultureInfo, object? argument)
{
return argument is Type t && t.IsAssignableTo(typeof(Window))
? ((Window)Activator.CreateInstance(t)!).Title
: null;
}
}
// Custom function with numeric input
public class DoubleValueFunction : OneDoubleFunction
{
public override double? Evaluate(CultureInfo cultureInfo, double x)
{
return x * 2;
}
}
// Custom function with two arguments
public class PowerFunction : TwoArgFunction
{
public override object? Evaluate(CultureInfo cultureInfo, object? x, object? y)
{
if (TryConvert(x, out var baseVal) && TryConvert(y, out var exp))
return Math.Pow(baseVal, exp);
return null;
}
}
// Custom function with variable arguments
public class SumFunction : ArbitraryArgFunction
{
public override object? Evaluate(CultureInfo cultureInfo, Func