BooleanValueInverter

This package consists of three .NET libraries – one for Windows Phone, one for Windows Store Apps, and one for WPF projects – that all contain an implementation of the BooleanValueInverter class.

BooleanValueInverter is a simple implementation of IValueConverter that inverts (negates) boolean values. In addition, it can process an additional IValueConverter instance that is passed as ConverterParameter and calls this converter’s Convert method before or after the inverting operation, depending on whether the additional converter expects a boolean value as input, or produces a boolean value as output.

The package is available for Windows Phone 7.1, 8.0 and higher, Windows Store Apps for Windows 8.0 and higher, as well as WPF .NET 4.0, 4.5 and higher. It is released under the Apache License 2.0. The package is available on Nuget (https://www.nuget.org/packages/BooleanValueInverter/). To install BooleanValueInverter, run the following command in the Package Manager Console:

PM> Install-Package BooleanValueInverter

Usage Examples:

Registration of the Inverter class within App / Page / Window resources:

<Application | PhoneApplicationPage | Page | Window>
	x:Class="..."
	xmlns:xamlInverter="clr-namespace:XamlInverter;assembly=XamlInverter"
	...other attributes go here...>

<Application | PhoneApplicationPage | Page | Window.Resources>
	<BooleanValueInverter x:Key="Inverter" />
	<!-- additional converters and other resources follow here... -->
</Application | PhoneApplicationPage | Page | Window.Resources>

Usage within data binding markup extension tags:

Usage as simple inverter, to negate a binding to a boolean property (for example to bind to any UserControl’s IsEnabled property):

<UserControl IsEnabled="{Binding BooleanProperty, Converter={StaticResource Inverter}}" />

Usage in combination with an additional converter that accepts a boolean value as input (for example to bind to any UserControl’s Visibility property). In this case, the boolean input property will be negated first, the negated value will then be passed to the additional converter (in this example, BooleanToVisibilityConverter) and the final result will be used for data binding:

<UserControl Visibility="{Binding BooleanProperty, Converter={StaticResource Inverter}, ConverterParameter={StaticResource BooleanToVisibilityConverter}}" />

Usage in combination with an additional converter that produces a boolean value as output (for example to bind a non-boolean value to any UserControl’s IsEnabled property). In this case, the non-boolean input property will be passed to the additional converter first, then this converter’s result (a boolean value) will be negated, and finally this negated boolean value will be used for data binding:

<UserControl IsEnabled="{Binding NonBooleanProperty, Converter={StaticResource Inverter}, ConverterParameter={StaticResource AnythingToBooleanConverter}}" />