Table of Contents

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

LocalizeEnumConverter

KeyPrefix

Gets or sets the prefix prepended to the generated resource key. Defaults to Enum_.

public string KeyPrefix { get; set; }

Property Value

string

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

ResourceManager

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

values 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.

targetType Type

The type of the binding target property.

parameter object

An optional converter parameter; not used.

culture CultureInfo

The 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

value object

The value produced by the binding target.

targetTypes Type[]

The types to convert back to.

parameter object

An optional converter parameter; not used.

culture CultureInfo

The culture supplied by the binding; not used.

Returns

object[]

Never returns; always throws.

Exceptions

NotSupportedException

Always thrown; the converter is one-way.