Class LocalizeExtension
- Namespace
- RentADeveloper.ResXLocalization.Avalonia
- Assembly
- ResXLocalization.Avalonia.dll
XAML markup extension that produces a binding to a localized string, re-resolving automatically
whenever Current changes culture. Usage in XAML:
{l:Localize {x:Static res:StringsKeys.Greeting}} for a typed key,
{l:Localize SomeKey} for a key-only lookup across all registered resource managers, or
{l:Localize Key=SomeKey, ResourceManager={x:Static res:Strings.ResourceManager}} to scope
the lookup to one file. When the resource value is a composite format string, supply its
arguments by binding the LocalizeArgs attached properties on the target element.
public sealed class LocalizeExtension : MarkupExtension
- Inheritance
-
MarkupExtensionLocalizeExtension
- Inherited Members
Constructors
LocalizeExtension()
Initializes a new instance of the LocalizeExtension class.
public LocalizeExtension()
LocalizeExtension(object)
Initializes a new instance of the LocalizeExtension class from a single positional
argument. A typed ResourceKey (for example from
{x:Static res:StringsKeys.Greeting}) becomes ResourceKey; a
string becomes Key; any other value leaves Key empty.
A single object-typed constructor is used instead of overloads so Avalonia's positional-argument
resolution is never ambiguous, which also keeps the XAML previewer working.
public LocalizeExtension(object key)
Parameters
keyobjectA ResourceKey or a key string.
Properties
Key
Gets or sets the resource key to resolve. Used when ResourceKey is not set. If ResourceManager is also set, the lookup is scoped to that file; otherwise every registered resource manager is searched.
public string Key { get; set; }
Property Value
ResourceKey
Gets or sets a typed, file-scoped key. When set, it takes precedence over Key and ResourceManager and resolves through its own resource manager.
public ResourceKey? ResourceKey { get; set; }
Property Value
ResourceManager
Gets or sets the resource manager that scopes a Key lookup to a single
.resx file. Ignored when ResourceKey is set; when both this and
ResourceKey are unset, the key is searched across all registered resource managers.
public ResourceManager? ResourceManager { get; set; }
Property Value
Methods
ProvideValue(IServiceProvider)
Provides the value supplied to the target property: a binding whose value is the localized string for the configured key, updated live on every culture change - and, when the target is an Avalonia.AvaloniaObject, on every change of its LocalizeArgs arguments.
public override object ProvideValue(IServiceProvider serviceProvider)
Parameters
serviceProviderIServiceProviderThe service provider supplied by the XAML loader.
Returns
- object
An Avalonia binding that yields the localized string.