CoalesceConverter Class
Represents a value converter that returns the value if it is non-null; otherwise, the value of the converter's parameter.
[ValueConversion(typeof(object), typeof(object))]
public class CoalesceConverter
- Inheritance:
- object object
Remarks
This converter can also be used with MultiBinding objects. In which case, the first non-null value from the list of specified values is returned. If all the values are null, then the parameter is returned.
Constructors
CoalesceConverter()
Initializes an instance of the class.
public CoalesceConverter()
Methods
Convert(object, Type, object, CultureInfo)
Converts a value. The data binding engine calls this method when it propagates a value from the binding source to the binding target.
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.
Convert(object[], Type, object, CultureInfo)
Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.
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
|
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 first non-null value from
values
, otherwiseparameter
is returned.
ConvertBack(object, Type, object, CultureInfo)
Converts a value. The data binding engine calls this method when it propagates a value from the binding target to the binding source.
public object ConvertBack(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.
ConvertBack(object, Type[], object, CultureInfo)
Converts a binding target value to the source binding values.
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
Parameter | Type | Description |
---|---|---|
value | object | The value that the binding target produces. |
targetTypes | Type[] | The array of types to convert to. The array length indicates the number and types of values that are suggested for the method to return. |
parameter | object | The converter parameter to use. |
culture | CultureInfo | The culture to use in the converter. |
Returns
- object[]:
An array of values that have been converted from the target value back to the source values.