The ultimate converters pack for WPF, providing enough simple and flexible converters for all occasions.
- BoolConverter - Returns the result of the specified operation between 2 bool.
- BoolToObjectConverter - Returns the specified object according to the bool value.
- BoolToStringConverter - Returns the specified string according to the bool value.
- BoolToDoubleConverter - Returns the specified double value according to the bool value.
- BoolToVisibilityConverter - Returns the specified Visibility value according to the bool value.
- BoolToThicknessConverter - Returns the specified Thickness according to the bool value.
- BoolToBrushConverter - Returns the specified Brush according to the bool value.
- MathConverter - Performs the specified math operation between 2 double numbers.
- NumberComparisonConverter - Compares 2 double numbers using the specified operation.
- StringCaseConverter - Converts given string to a new one with the specified case.
- StringComparisonConverter - Compares 2 strings using the specified operation.
- StringFormatConverter - Formats given string with the specified argument(-s).
- ObjectToStringConverter - Returns a string of the specified object.
- ObjectComparisonConverter - Compares 2 objects using the specified operation.
- TypeConverter - Changes a type of the given object to the specified one.
- CollectionToStringConverter - Converts given Collection to the string using specified separator.
- CollectionToCountConverter - Returns the count of the given Collection.
- CollectionToItemConverter - Returns an item of the given Collection according to the specified its index.
- BrushToColorConverter - Returns a Color of the specified SolidColorBrush.
- ColorToBrushConverter - Converts the given Color to the SolidColorBrush.
- VisibilityToBoolConverter - Returns the specified bool value according to the Visibility value.
- UrlToImage - Converts the given url to the BitmapImage.
First of all install package using .NET CLI:
dotnet add package Hoax.WpfConverters --version 1.0.0
or add the following string to the .csproj file:
<PackageReference Include="Hoax.WpfConverters" Version="1.0.0" />
Add the namespace to your XAML header:
xmlns:c="clr-namespace:Hoax.WpfConverters;assembly=Hoax.WpfConverters"
Using BoolToVisibilityConverter
with custom behavior. If the binding value is true
, the border will be Hidden
, otherwise Visible
.
<Border Visibility="{Binding BoolValue,
Converter={c:BoolToVisibilityConverter ForTrue=Hidden, ForFalse=Visible}}" />
or you can add a converter to resources which is a more effiecient way to use the converter.
<Window.Resources>
<c:BoolToVisibilityConverter x:Key="BoolToVis" ForTrue="Hidden" ForFalse="Visible" />
</Window.Resources>
<Border Visibility="{Binding BoolValue, Converter={StaticResource BoolToVis}}" />
Each converter has a Then
property that takes an IValueConverter
value. The next converter will use the result of the previous one. You can build as long a chain of converters as you like.
This example shows a chain of 3 operations.
true
=>false
. TheIsEnabled
property of the button istrue
, so it becomesfalse
after theNOT
operation.false
=>False is the value after the NOT operation
. Formatsfalse
with given pattern. Tip: a string value offalse
is"False"
. If the pattern starts with{0}
you should add{}
at the beginning of the string. But if the pattern binds from a C# code, you don't need to add that.False is the value after the NOT operation
=>fALSE IS THE VALUE AFTER THE not OPERATION
. Inverts the case of the given string and set it to the Text property.
Note. You can use your own converters as a next converter, but if that converter doesn't extend the Hoax.WpfConveters.Base.ConverterBase
class, it won't be able to continue the chain and will be the last link.
<Button x:Name="btn"
IsEnabled="True" />
<TextBlock Text="{Binding IsEnabled, ElementName=btn,
Converter={c:BoolConverter Operation=Not,
Then={c:StringFormatConverter Format='{}{0} is the value after the NOT operation',
Then={c:StringCaseConverter Operation=Invert}}}}" />