ConditionalConverter Class
Represents a value and multi-value converter that provides if-else functionality for Binding and MultiBinding objects.
public class ConditionalConverter
- Inheritance:
- object object
Remarks
This converter expects the following source values to be specified:
- Condition - A bool value indicating whether the true or false value should be returned.
-
TrueValue - An object that is returned when the Condition is
true. This can be omitted if the FalseValue parameter is also omitted, in which case the value of theTrueValueproperty will be used. -
FalseValue - An object that is returned when the Condition is
false. This can be omitted, in which case the value of theFalseValueproperty will be used.
Examples
<MultiBinding Converter="{StaticResource ConditionalConverter}">
<Binding Path="IfConditionValue" />
<Binding Path="TrueValue" />
<Binding Path="FalseValue" />
</MultiBinding>
<shared:ConditionalConverter x:Key="ConditionalConverter" TrueValue="The Value is true" FalseValue="The Value is false" />
...
<TextBlock Text="{Binding Path=BooleanProperty, Converter={StaticResource ConditionalConverter}}" />
Constructors
ConditionalConverter()
Initializes an instance of the class.
public ConditionalConverter()
Properties
ConditionValue
The optional value to use for the conditional test.
FalseValue
The value returned when the conditional test is false.
TrueValue
The value returned when the conditional test is true.
Methods
Convert(object?, Type, object?, CultureInfo)
Converts a value.
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| value | object | The value produced by the binding source. |
| targetType | Type | The type of the binding target property. |
| parameter | object | The converter parameter to use. |
| culture | CultureInfo | The culture to use in the converter. |
Returns
- object:
A converted value. If the method returns
null, the valid null value is used.
Convert(object?[], Type, object?, CultureInfo)
Returns either the second or third source value, based on the first source value.
public object? Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| values | object[] | The array of values that the source bindings in the MultiBinding produces. The value System.Windows.DependencyProperty.UnsetValue indicates that the source binding has no value to provide for conversion. |
| targetType | Type | The type of the binding target property. |
| parameter | object | The converter parameter to use. |
| culture | CultureInfo | The culture to use in the converter. |
Returns
- object:
The second source value, if the first source value equals
true; otherwise the third source value.
ConvertBack(object?, Type, object?, CultureInfo)
Converts a value.
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| value | object | The value that is produced by the binding target. |
| targetType | Type | The type to convert to. |
| parameter | object | The converter parameter to use. |
| culture | CultureInfo | The culture to use in the converter. |
Returns
- object:
A converted value. If the method returns
null, the valid null value is used.
ConvertBack(object?, Type[], object?, CultureInfo)
This method always returns null and should not be used.
public object?[]? ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| value | object | Not used. |
| targetTypes | Type[] | Not used. |
| parameter | object | Not used. |
| culture | CultureInfo | Not used. |
Returns
- object[]:
null.
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()