This Library contains various common implementations of the IValueConverter interface for WPF and UWP apps:
- BooleanConverter: Converts
true/falseto the values specified by the propertiesTrueValueandFalseValue. ABooleanToVisibilityConvertercould be implemented like this:
<sxc:BooleanConverter x:Key="BooleanToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/>- BooleanInverter: Converts
truetofalseand vice versa. - BooleanToVisibilityConverter: Converts
true/falsetoVisible/Collapsed(orHidden). - EqualsConverter: Returns
truewhenvalueandparameterare equal (according to theEqualsmethod). In WPF the converter can also be used asIMultiValueConverterto compare two values bound viaMultiBinding. - NullConverter: Returns
truewhenvalueisnull, otherwisefalse. Empty strings can be treated as null by settings theTreatEmptyStringAsNullproperty totrue. - StringFormatConverter: Formats
valueusingparameteras format string. The formatting of empty strings can be controlled with theFormatEmptyStringproperty. - EmptyConverter: Checks if
valueis an emptyIEnumerable. TheTreatNullAsEmptyproperty can be set totrueorfalse. - ContainsConverter: Checks if
IEnumerablepassed asvaluecontainsparameter. In WPF the converter can also be used asIMultiValueConverterto 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
BooleanToVisibilityConvertercould be implemented like this:
<sxc:ConverterChain x:Key="NullToVisibilityConverter">
<sxc:NullConverter/>
<sxc:BooleanInverter/>
<sxc:BooleanToVisibilityConverter/>
</vpc:ConverterChain>