This Library contains various common implementations of the IValueConverter
interface for WPF and UWP apps:
- BooleanConverter: Converts
true
/false
to the values specified by the propertiesTrueValue
andFalseValue
. ABooleanToVisibilityConverter
could be implemented like this:
<sxc:BooleanConverter x:Key="BooleanToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/>
- BooleanInverter: Converts
true
tofalse
and vice versa. - BooleanToVisibilityConverter: Converts
true
/false
toVisible
/Collapsed
(orHidden
). - EqualsConverter: Returns
true
whenvalue
andparameter
are equal (according to theEquals
method). In WPF the converter can also be used asIMultiValueConverter
to compare two values bound viaMultiBinding
. - NullConverter: Returns
true
whenvalue
isnull
, otherwisefalse
. Empty strings can be treated as null by settings theTreatEmptyStringAsNull
property totrue
. - StringFormatConverter: Formats
value
usingparameter
as format string. The formatting of empty strings can be controlled with theFormatEmptyString
property. - EmptyConverter: Checks if
value
is an emptyIEnumerable
. TheTreatNullAsEmpty
property can be set totrue
orfalse
. - ContainsConverter: Checks if
IEnumerable
passed asvalue
containsparameter
. In WPF the converter can also be used asIMultiValueConverter
to compare two bound values. - MappingConverter: This converter enables the definition of the mapping directly in XAML (which is especially useful for enums):
<sxc:MappingConverter x:Key="StateConverter">
<sxc:Mapping From="{x:Static common:State.Created}" To="Waiting..."/>
<sxc:Mapping From="{x:Static common:State.InProgress}" To="In progress..."/>
<sxc:Mapping From="{x:Static common:State.Finished}" To="Finished"/>
</sxc:MappingConverter>
- ConverterChain: This converter can be used to execute multiple converters in row. A
BooleanToVisibilityConverter
could be implemented like this:
<sxc:ConverterChain x:Key="NullToVisibilityConverter">
<sxc:NullConverter/>
<sxc:BooleanInverter/>
<sxc:BooleanToVisibilityConverter/>
</vpc:ConverterChain>