Class LocalizeEnumConverter
- Namespace
- RentADeveloper.ResXLocalization.Avalonia
- Assembly
- ResXLocalization.Avalonia.dll
Multi-value converter that localizes an enumeration value bound as a real value (rather than as a
DataContext). Use it in a MultiBinding whose first binding is the enumeration value
and whose second binding is CurrentCulture, so the result re-converts on
every culture change. The value is mapped to a resource key using the convention
{KeyPrefix}{EnumTypeName}_{Value}.
public sealed class LocalizeEnumConverter : IMultiValueConverter
- Inheritance
-
LocalizeEnumConverter
- Implements
-
IMultiValueConverter
- Inherited Members
Constructors
LocalizeEnumConverter()
Initializes a new instance of the LocalizeEnumConverter class.
public LocalizeEnumConverter()
Properties
Default
Gets the shared, search-all converter instance with default settings. Reference it from XAML
as {x:Static l:LocalizeEnumConverter.Default} when no file scoping is required. The
shared instance is read-only - create your own converter to customize
KeyPrefix or ResourceManager.
public static LocalizeEnumConverter Default { get; }
Property Value
KeyPrefix
Gets or sets the prefix prepended to the generated resource key. Defaults to Enum_.
public string KeyPrefix { get; set; }
Property Value
Exceptions
- ArgumentNullException
The supplied value is null.
- InvalidOperationException
The converter is the shared Default instance, which is read-only.
ResourceManager
Gets or sets the resource manager that scopes the lookup to a single .resx file. When
unset, the generated key is searched across all registered resource managers.
public ResourceManager? ResourceManager { get; set; }
Property Value
Exceptions
- InvalidOperationException
The converter is the shared Default instance, which is read-only.
Methods
Convert(IList<object?>, Type, object?, CultureInfo)
Converts the bound enumeration value to its localized string.
public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
Parameters
valuesIList<object>The bound values. The first element is expected to be the Enum value to localize; any further bindings (such as the current culture) exist only to trigger re-conversion.
targetTypeTypeThe type of the binding target property.
parameterobjectAn optional converter parameter; not used.
cultureCultureInfoThe culture supplied by the binding; not used (the active culture is taken from Current).