RussJudge.WPFValueConverters 1.1.0

dotnet add package RussJudge.WPFValueConverters --version 1.1.0
NuGet\Install-Package RussJudge.WPFValueConverters -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RussJudge.WPFValueConverters" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RussJudge.WPFValueConverters --version 1.1.0
#r "nuget: RussJudge.WPFValueConverters, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RussJudge.WPFValueConverters as a Cake Addin
#addin nuget:?package=RussJudge.WPFValueConverters&version=1.1.0

// Install RussJudge.WPFValueConverters as a Cake Tool
#tool nuget:?package=RussJudge.WPFValueConverters&version=1.1.0

RussJudge.WPFValueConverters

A collection of ValueConverters that I've built over the years.

All these are ValueConverters to be added to the Xaml of a WPF control.

For examples on how to use these ValueConverters, please see the example project on the Github repository page at https://github.com/russjudge/RussJudge.WPFValueConverters.

BooleanToBrushAnimationConverter

This converter will take a boolean value and generate a System.Windows.Media.SolidColorBrush. Based on the parameters provided, the brush can be animated. See the addendum to this readme for details on these parameters.

Parameter syntax:

ConverterParameter='<boolValueToMatch-default true>|<brush definition on match>|<brush definiton on mismatch>'

BytesToMBFormatter

This converts an int64 number into a string formatted by culture. It assumes the number represents bytes and divides by factors of 1024 to represent KB, MB, GB, TB, PB, or EB so that the result is a number greater than 1 and less than 1,024.

For example, if the number is 248332132, you will convert this to 236.0MB.

CurrencyFormatter

This converter takes a number and formats it to a currency value based on the culture. For example, in the US, 233888.23 will convert to $233,888.23.

DateFormatter

This converter takes a datetime value and formats it to a human-readable format based on the culture or using the format passed as the converter parameter.

Parameter syntax (optional):

ConverterParameter='<Standard date/time format codes>'

FalseBoolToVisibilityConverter

Converts a boolean value to Visibility, false being Visible, while true is Collapsed. This is to produce the opposite behavior to BooleanToVisibilityConverter.

FullFilePathToNameConverter

This converts a string that represents the full path to a file. The result will be simply the file name excluding the path to that file.

NullToAnimatedBrushConverter

Converts a nullable object to a SolidColorBrush. The brush will depend on the parameters passed and can define one brush for a null value and another brush for a non-null value. If the value is an empty string, it will return the same as if the value were null.

Parameter Syntax:

ConverterParameter='<BrushIfNull>|<BrushIfNotNull>'

NullToVisibilityConverter

Converts a nullable objects to Visibility, based on parameters passed.

Parameter Syntax:

ConverterParameter='<VisibilityIfNull>|<VisibilityIfNotNull>'

NumberFormatter

Formats a number, based on the culture and parameters passed.

Parameter Syntax (optional):

ConverterParameter='<Standard number format codes>'

NumericAdjustmentConverter

Deprecated Use NumericMathConverter instead.

Adds a value to a number, set by the parameter. A negative number can be added to the value.

Parameter Syntax:

ConverterParameter='<NumberToAdd>'

NumericComparisonToBrushAnimationConverter

Compares a numeric value to a number in the parameter and converts to a brush.

Parameter Syntax: ConverterParameter='<operator>|<comparisonValueMatch>|<brushOnTrue>|<brushOnFalse>'

NumericComparisonToVisibilityConverter

Compares a numeric value to a number in the parameter and converts to visibility.

Parameter Syntax: ConverterParameter='<operator>|<comparisonValueMatch>|<VisibilityOnTrue>|<VisibilityOnFalse>'

NumericMathConverter

Adjusts a bound value by a number, set by the parameter. See the Addendum for valid Math Operators.

Parameter Syntax:

ConverterParameter='<mathOperator>|<NumberToAdd>'

OppositeBooleanConverter

Converts a boolean to the opposite value.

PathToImageSourceConverter

Converts the path to an image file to a BitmapImage.

Parameter Syntax (optional): ConverterParameter='<pathToImageIfImagePathNotFound>|<pathToImageIfImagePathErrors>'

Default "Image Not found" and "Image error" are provided, but can be overridden by either passing the path to these images in the parameter, or by setting them in the code-behind as follows:

PathToImageSourceConverter.ImageNotAvailableImage = new Uri("pack://application:,,,/RussJudge.WPFValueConverters;component/Resources/ImageNotAvailable.png", UriKind.RelativeOrAbsolute);
PathToImageSourceConverter.ImageErrorImage = new Uri("pack://application:,,,/RussJudge.WPFValueConverters;component/Resources/ImageError.png", UriKind.RelativeOrAbsolute);

SecondsToTimeSpanConverter

Converts a number of seconds (type double) to a TimeSpan and formats it based on the parameter passed and culture.

Parameter Syntax (optional): ConverterParameter='<StandardDate/timeFormatCode>'

StringReplacementConverter

Replace all occurrences of a part of a string to another string.

Parameter Syntax: ConverterParameter='<stringToMatch>|<stringToReplaceTo>'

ValueMatchToAnimatedBrushConverter

Converts a value to a brush based on matching on the parameter. The value is converted to a string (.ToString()) to perform the match.

Parameter Syntax: ConverterParameter='<operator>|<comparisonValueMatch>|<brushOnTrue>|<brushOnFalse>'

ValueMatchToVisibilityConverter

Converts a value to visibility based on matching on the parameter. The value is converted to a string (.ToString()) to perform the match.

Parameter Syntax: ConverterParameter='<operator>|<comparisonValueMatch>|<visibilityOnTrue>|<visibilityOnFalse>'

Addendum

Parameter delimiters

Multiple Converter parameters are delimited by "|". Brush definition parameters are delimited by semi-colon (";").

Brush animation parameters and syntax

Parameters are case-insensitive.

Example: FROMCOLOR=Red;TOCOLOR=Blue;REPEATCOUNT=Forever;DURATION=1000;AUTOREVERSE=True

Setting Description
DEFAULT Set brush to default value. No other parameters can be set.
COLOR=<value> Sets the brush to a solid color. All other parameters are ignored.
FROMCOLOR=<value> Sets the starting color for an animated brush.
TOCOLOR=<value> Sets the ending color for an animated brush.
REPEATCOUNT=<value> The number of times to repeat the animation. Set to "Forever" to repeat forever.
AUTOREVERSE=<value> Whether or not to auto-reverse the animation. Valid values are "True" and "False".

Comparison operators

An operator will always be followed by the comparison value, such that it will work as <boundValue> &gtl;operator> <comparisonValue>, where <operator> and <comparisonValue> are set by ConverterParameter='<operator>|<comparisonValue>'.

Valid operators:

Operator Description
< (or '&lt;') Bound value less than comparison value
<= (or '&lt;=') Bound value less than or equal to comparison value
> (or '&gt;') Bound value greater than comparison value
>= (or '&gt;=') Bound value greater than or equal to comparison value
= Bound value equal to comparison value
!= Bound value not equal to comparison value

Math operators

As with comparison operators, a matho operator will always be followed by a numeric value to apply to the bound value. The bound value must be numeric.

For bitwise operators, the bound value will be converted to a long before applying the operator and the parameter value. For math operators, the value is converted to a double before applying the paramter value.

Valid operators:

Operator Description
+ Add to the bound value
- Subtract from the bound value
* Multiply to the bound value
/ divide from the bound value
% return the modulo of the bound value and parameter
pow return the power of the parameter to the bound value
abs return the absolute value of the bound value (adjustment value parameter is ignored)
sin return the sine of the bound value (adjustment value parameter is ignored)
sinh return the hyperbolic sine of the bound value (adjustment value parameter is ignored)
cos return the cosine of the bound value (adjustment value parameter is ignored)
cosh return the hyperbolic cosine of the bound value (adjustment value parameter is ignored)
cbrt return the cube root of the bound value (adjustment value parameter is ignored)
min return the smaller of the bound value versus the adjustment parameter value
max return the smaller of the bound value versus the adjustment parameter value
acos return the angle whose cosine is the bound value (adjustment value parameter is ignored)
acosh return the angle whose hyperbolic cosine is the bound value (adjustment value parameter is ignored)
asin return the angle whose sine is the bound value (adjustment value parameter is ignored)
asinh return the angle whose hyperbolic sine is the bound value (adjustment value parameter is ignored)
tan return the tangent of the bound value (adjustment value parameter is ignored)
tanh return the hyperbolic tangent of the bound value (adjustment value parameter is ignored)
atan return the angle whose tangent is the bound value (adjustment value parameter is ignored)
atanh return the angle whose hyperbolic tangent is the bound value (adjustment value parameter is ignored)
atan2 return the angle whose tangent is the quotent between the bound value and the adjustment value parameter
ceiling returns the smallest integral greater than or equal to the bound value (adjustment value parameter is ignored)
floor returns the largest integral less than or equal to the bound value (adjustment value parameter is ignored)
round returns the bound value rounded by to the number of decimal places specified by the adjustment value parameter
sqrt returns the square root of the bound value (adjustment value parameter is ignored)
log returns the logarithm of the bound value where the base value is the adjustment value.
& returns a bitwise "and" operation with the adjustment value
\ returns a bitwise "or" operation with the adjustment value.
^ returns a bitwise "xor" operation with the adjustment value.
<< (or &lt;&lt;) left-shift the bound value by the adjustment value
>> (or &gt;&gt;) right-shift the bound value by the adjustment value
>>> (or &gt;&gt;&gt;) unsigned right-shift the bound value by the adjustment value
Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 186 12/14/2023
1.0.0 111 12/13/2023

Added "NumericMathConverter"
Deprecated "NumericAdjustmentConverter"
Updated Example to demonstrate NumericMathConverter
Tweaked visual representation of MainWindow of Example.
Updated Readme.md.