Class LocalizeEnumExtension
- Namespace
- RentADeveloper.ResXLocalization.WPF
- Assembly
- ResXLocalization.WPF.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
-
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
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.
public Collection<Argument> Arguments { get; }
Property Value
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
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
Value
Gets or sets the enumeration value to localize: a plain 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.
public object? Value { get; set; }
Property Value
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
serviceProviderIServiceProviderThe service provider supplied by the XAML loader.
Returns
- object
The binding expression of a WPF multi-binding that yields the localized string, or the multi-binding itself when the target is not a dependency property, such as a Setter value. Inside a XAML designer that supplies the target property as a CLR property instead of a dependency property, such as Rider's WPF previewer, a string instead, without validation: the lookup of a constant Enum Value without arguments, or an empty string for any other Value.