Class EnumToBoolConverter
Converts an enum value to true when it equals the
converter parameter (the parameter is a string parsed against the bound
enum's type). The reverse direction returns the parsed enum value when
fed true, and Avalonia.Data.BindingOperations.DoNothing
otherwise — which is what makes a group of RadioButtons correctly
act as a single-selection over an enum-valued property:
IsChecked="{Binding Source, Mode=TwoWay,
Converter={x:Static converters:EnumToBoolConverter.Instance},
ConverterParameter=Manual}"
Each radio's IsChecked turns into "Source == Manual"; flipping a radio on emits "Manual" back into the binding, which selects that radio and deselects the others (because the others now bind to false).
Implements
Inherited Members
Namespace: MOSAIC.Converters
Assembly: MOSAIC.dll
Syntax
public sealed class EnumToBoolConverter : IValueConverter
Fields
Instance
Shared singleton — used as {x:Static converters:EnumToBoolConverter.Instance}.
Declaration
public static readonly EnumToBoolConverter Instance
Field Value
| Type | Description |
|---|---|
| EnumToBoolConverter |
Methods
Convert(object?, Type, object?, CultureInfo)
Converts a value.
Declaration
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value to convert. |
| Type | targetType | The type of the target. |
| object | parameter | A user-defined parameter. |
| CultureInfo | culture | The culture to use. |
Returns
| Type | Description |
|---|---|
| object | The converted value. |
Remarks
This method should not throw exceptions. If the value is not convertible, return a Avalonia.Data.BindingNotification in an error state. Any exceptions thrown will be treated as an application exception.
ConvertBack(object?, Type, object?, CultureInfo)
Converts a value.
Declaration
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value to convert. |
| Type | targetType | The type of the target. |
| object | parameter | A user-defined parameter. |
| CultureInfo | culture | The culture to use. |
Returns
| Type | Description |
|---|---|
| object | The converted value. |
Remarks
This method should not throw exceptions. If the value is not convertible, return a Avalonia.Data.BindingNotification in an error state. Any exceptions thrown will be treated as an application exception.