Class LocalizeEnumConverter
- Namespace
- RentADeveloper.ResXLocalization.WPF
- Assembly
- ResXLocalization.WPF.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
- 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(object?[], Type, object?, CultureInfo)
Converts the bound enumeration value to its localized string.
public object Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture)
Parameters
valuesobject[]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).
Returns
- object
The localized string for the enumeration value, or Empty when no value is supplied or the first value is not an Enum.
ConvertBack(object?, Type[], object?, CultureInfo)
Not supported; this converter is one-way.
public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture)
Parameters
valueobjectThe value produced by the binding target.
targetTypesType[]The types to convert back to.
parameterobjectAn optional converter parameter; not used.
cultureCultureInfoThe culture supplied by the binding; not used.
Returns
- object[]
Never returns; always throws.
Exceptions
- NotSupportedException
Always thrown; the converter is one-way.