Class LocalizeEnumExtension

Namespace
RentADeveloper.ResXLocalization.Avalonia
Assembly
ResXLocalization.Avalonia.dll

XAML markup extension that localizes an enumeration value, re-resolving automatically on every change of the value and of RefreshTriggeringRevision of Current. The value is mapped to a resource key by EnumKeyBuilder, by default {KeyPrefix}{EnumTypeName}{Value}. Usage in XAML: {l:LocalizeEnum Value={Binding SortOrder}} (or the shorthand {l:LocalizeEnum {Binding SortOrder}}) for a bound value, {l:LocalizeEnum Value={Binding}} in an item template whose item is the enumeration value, or {l:LocalizeEnum Value={x:Static m:FileSortOrder.Ascending}} for a fixed member. When the resource value is a composite format string, supply its arguments as Argument child elements: <l:LocalizeEnum Value="{Binding SortOrder}" KeyPrefix="Count"><l:Argument Value="{Binding FileCount}" /></l:LocalizeEnum>.

public sealed class LocalizeEnumExtension : MarkupExtension
Inheritance
MarkupExtension
LocalizeEnumExtension
Inherited Members

Constructors

LocalizeEnumExtension()

Initializes a new instance of the LocalizeEnumExtension class.

public LocalizeEnumExtension()

LocalizeEnumExtension(object)

Initializes a new instance of the LocalizeEnumExtension class and sets Value: {l:LocalizeEnum {Binding SortOrder}} is {l:LocalizeEnum Value={Binding SortOrder}}.

public LocalizeEnumExtension(object value)

Parameters

value object

The enumeration value: a binding or a constant Enum member.

Properties

Arguments

Gets the format arguments, in declaration order: the Argument child elements. The first argument is {0}, the second {1}, and so on, whether it has a name or not. The enumeration value itself is not an argument; bind it as an Argument when the text needs it.

[Content]
public Collection<Argument> Arguments { get; }

Property Value

Collection<Argument>

KeyPrefix

Gets or sets the key prefix passed to EnumKeyBuilder. null (the default) means "the EnumKeyBuilder decides", which by default is Enum_; a value overrides the prefix for this extension.

public string? KeyPrefix { get; set; }

Property Value

string

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

Value

Gets or sets the enumeration value to localize: a binding, such as {Binding SortOrder} or {Binding} in an item template, or a constant member written as {x:Static m:FileSortOrder.Ascending}. A bound value that is not an Enum, such as null, renders an empty string.

[AssignBinding]
public object? Value { get; set; }

Property Value

object

Methods

ProvideValue(IServiceProvider)

Provides the value supplied to the target property: a binding whose value is the localized string for Value, formatted with Arguments, updated live on every change of the value, of the arguments and of RefreshTriggeringRevision.

public override object ProvideValue(IServiceProvider serviceProvider)

Parameters

serviceProvider IServiceProvider

The service provider supplied by the XAML loader; not used.

Returns

object

An Avalonia multi-binding that yields the localized string.

Exceptions

InvalidOperationException

Value is null or a constant that is not an Enum; or an Argument has no Value, an empty Name, or the same name as another one.