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.
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)
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 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 first non-null value from
values, otherwiseparameteris returned.
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)
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.
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()