BindingValue<T> Struct
Definition
A value passed into a binding.
public struct BindingValue<T>
Remarks
The avalonia binding system is typed, and as such additional state is stored in this structure. A binding value can be in a number of states, described by the Avalonia.Data.BindingValue<T>.Type property:
- Avalonia.Data.BindingValueType.Value: a simple value
- Avalonia.Data.BindingValueType.UnsetValue: the target property will revert to its unbound state until a new binding value is produced. Represented by Avalonia.AvaloniaProperty.UnsetValue in an untyped context
- Avalonia.Data.BindingValueType.DoNothing: the binding value will be ignored. Represented by Avalonia.Data.BindingOperations.DoNothing in an untyped context
- Avalonia.Data.BindingValueType.BindingError: a binding error, such as a missing source property, with an optional fallback value
- Avalonia.Data.BindingValueType.DataValidationError: a data validation error, with an optional fallback value
To create a new binding value you can:
- For a simple value, call the Avalonia.Data.BindingValue<T> constructor or use an implicit
conversion from
T - For an unset value, use Avalonia.Data.BindingValue<T>.Unset or simply
default - For other types, call one of the static factory methods
Constructors
| Name | Description |
|---|---|
| BindingValue<T> | Initializes a new instance of the Avalonia.Data.BindingValue<T> struct with a type of Avalonia.Data.BindingValueType.Value |
BindingValue<T> Constructor
Initializes a new instance of the Avalonia.Data.BindingValue<T> struct with a type of Avalonia.Data.BindingValueType.Value
public BindingValue<T>(T value)
Parameters
value T
The value.
Methods
BindingError overloads
BindingError Method
Returns a binding value with a type of Avalonia.Data.BindingValueType.BindingError.
public Avalonia.Data.BindingValue<T><T> BindingError(Exception e)
Parameters
e Exception
The binding error.
Returns
Avalonia.Data.BindingValue<T><T>
BindingError Method
public Avalonia.Data.BindingValue<T><T> BindingError(Exception e, Avalonia.Data.Optional<T><T> fallbackValue)
Parameters
e Exception
fallbackValue Avalonia.Data.Optional<T><T>
Returns
Avalonia.Data.BindingValue<T><T>
BindingError Method
Returns a binding value with a type of Avalonia.Data.BindingValueType.BindingErrorWithFallback.
public Avalonia.Data.BindingValue<T><T> BindingError(Exception e, T fallbackValue)
Parameters
e Exception
The binding error.
fallbackValue T
The fallback value.
Returns
Avalonia.Data.BindingValue<T><T>
DataValidationError overloads
DataValidationError Method
Returns a binding value with a type of Avalonia.Data.BindingValueType.DataValidationError.
public Avalonia.Data.BindingValue<T><T> DataValidationError(Exception e)
Parameters
e Exception
The data validation error.
Returns
Avalonia.Data.BindingValue<T><T>
DataValidationError Method
public Avalonia.Data.BindingValue<T><T> DataValidationError(Exception e, Avalonia.Data.Optional<T><T> fallbackValue)
Parameters
e Exception
fallbackValue Avalonia.Data.Optional<T><T>
Returns
Avalonia.Data.BindingValue<T><T>
DataValidationError Method
Returns a binding value with a type of Avalonia.Data.BindingValueType.DataValidationErrorWithFallback.
public Avalonia.Data.BindingValue<T><T> DataValidationError(Exception e, T fallbackValue)
Parameters
e Exception
The data validation error.
fallbackValue T
The fallback value.
Returns
Avalonia.Data.BindingValue<T><T>
Equals overloads
Equals Method
public bool Equals(Avalonia.Data.BindingValue<T><T> other)
Parameters
other Avalonia.Data.BindingValue<T><T>
Returns
bool
Equals Method
public bool Equals(object obj)
Parameters
obj object
Returns
bool
FromUntyped overloads
FromUntyped Method
Creates a Avalonia.Data.BindingValue<T> from an object, handling the special values Avalonia.AvaloniaProperty.UnsetValue, Avalonia.Data.BindingOperations.DoNothing and Avalonia.Data.BindingNotification.
public Avalonia.Data.BindingValue<T><T> FromUntyped(object value)
Parameters
value object
The untyped value.
Returns
Avalonia.Data.BindingValue<T><T>
The typed binding value.
FromUntyped Method
Creates a Avalonia.Data.BindingValue<T> from an object, handling the special values Avalonia.AvaloniaProperty.UnsetValue, Avalonia.Data.BindingOperations.DoNothing and Avalonia.Data.BindingNotification.
public Avalonia.Data.BindingValue<T><T> FromUntyped(object value, Type targetType)
Parameters
value object
The untyped value.
targetType Type
The runtime target type.
Returns
Avalonia.Data.BindingValue<T><T>
The typed binding value.
GetHashCode Method
public int GetHashCode()
Returns
int
GetValueOrDefault overloads
GetValueOrDefault Method
Gets the value of the binding value if present, otherwise the default value.
public TResult GetValueOrDefault<TResult>()
Returns
T
The value.
GetValueOrDefault Method
Gets the value of the binding value if present, otherwise a default value.
public T GetValueOrDefault(T defaultValue)
Parameters
defaultValue T
The default value.
Returns
T
The value.
GetValueOrDefault Method
public TResult GetValueOrDefault<TResult>(TResult defaultValue)
Parameters
defaultValue TResult
Type Parameters
TResult
Returns
TResult
ToOptional Method
Converts the binding value to an Avalonia.Data.Optional<T>.
public Avalonia.Data.Optional<T><T> ToOptional()
Returns
Avalonia.Data.Optional<T><T>
ToString Method
public string ToString()
Returns
string
ToUntyped Method
Converts the value to untyped representation, using Avalonia.AvaloniaProperty.UnsetValue, Avalonia.Data.BindingOperations.DoNothing and Avalonia.Data.BindingNotification where appropriate.
public object ToUntyped()
Returns
object
The untyped representation of the binding value.
WithValue Method
Returns a new binding value with the specified value.
public Avalonia.Data.BindingValue<T><T> WithValue(T value)
Parameters
value T
The new value.
Returns
Avalonia.Data.BindingValue<T><T>
The new binding value.
Exceptions
Properties
| Name | Description |
|---|---|
| DoNothing | Returns a binding value with a type of Avalonia.Data.BindingValueType.DoNothing. |
| Error | Gets the binding or data validation error. |
| HasError | Gets a value indicating whether the binding value represents either a binding or data validation error. |
| HasValue | Gets a value indicating whether the binding value has a value. |
| Type | Gets the type of the binding value. |
| Unset | Returns a binding value with a type of Avalonia.Data.BindingValueType.UnsetValue. |
| Value | Gets the binding value or fallback value. |
DoNothing Property
Returns a binding value with a type of Avalonia.Data.BindingValueType.DoNothing.
public Avalonia.Data.BindingValue<T><T> DoNothing { get; set; }
Error Property
Gets the binding or data validation error.
public Exception Error { get; set; }
HasError Property
Gets a value indicating whether the binding value represents either a binding or data validation error.
public bool HasError { get; set; }
HasValue Property
Gets a value indicating whether the binding value has a value.
public bool HasValue { get; set; }
Type Property
Gets the type of the binding value.
public Avalonia.Data.BindingValueType Type { get; set; }
Unset Property
Returns a binding value with a type of Avalonia.Data.BindingValueType.UnsetValue.
public Avalonia.Data.BindingValue<T><T> Unset { get; set; }
Value Property
Gets the binding value or fallback value.
public T Value { get; set; }