Table of Contents

Class ResourceExtension

Namespace
Acuit.Pinpoint.Windows
Assembly
Acuit.Pinpoint.Windows.dll

XAML extension for retrieving a resource string.

public class ResourceExtension : MarkupExtension
Inheritance
ResourceExtension
Inherited Members

Remarks

Using this namespace:

xmlns:apw="clr-namespace:Acuit.Pinpoint.Windows;assembly=Acuit.Pinpoint.Windows"

Use it like this:

<Label Content="{apw:Resource name}" />

Or, using the AsSpan property:

<TextBlock><apw:ResourceExtension Name="name" AsSpan="true" /></TextBlock>

In your Application-derived class constructor, add the following code:

ResourceExtension.RegisterResourceManager(null, [your namespace].Properties.Resources.ResourceManager);

The current thread's CurrentUICulture is used to determine which language resource to retrieve. Use something like SetCurrentThreadUICulture(string) to set each thread's CurrentUICulture.

Constructors

ResourceExtension()

Initializes a new instance of the ResourceExtension class.

public ResourceExtension()

ResourceExtension(string)

Initializes a new instance of the ResourceExtension class.

public ResourceExtension(string name)

Parameters

name string

The resource name.

Properties

AsSpan

Gets or sets whether to return a Span with formatted inlines.

public bool AsSpan { get; set; }

Property Value

bool

Examples

For example, the following could be the value for a resource named "TestWarning":

<Bold>WARNING:</Bold> Clicking the Test button will initiate a test.<LineBreak/>There will be <Span Foreground="Red">HIGH VOLTAGE</Span> at the test leads!

Then, assuming this namespace in the XAML:

xmlns:apw="clr-namespace:Acuit.Pinpoint.Windows;assembly=Acuit.Pinpoint.Windows"

The resource could be used like this:

<TextBlock><apw:ResourceExtension Name="TestWarning" AsSpan="true" /></TextBlock>

Remarks

When this property is true, the resource is assumed to be a string that represents the inner content of a Span, with inlines to provide formatting. When the resource value is obtained, a Span will be returned instead of a string.

Manager

Gets or sets the name of the resource manager to check first when retrieving the resource value.

public string Manager { get; set; }

Property Value

string

Remarks

If the resource is not found in this resource manager, then all other resource managers are checked next (in the order in which they were registered).

Name

Gets or sets the resource name.

[ConstructorArgument("name")]
public string Name { get; set; }

Property Value

string

Methods

ProvideValue(IServiceProvider)

When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.

public override object ProvideValue(IServiceProvider serviceProvider)

Parameters

serviceProvider IServiceProvider

A service provider helper that can provide services for the markup extension.

Returns

object

The object value to set on the property where the extension is applied.

RegisterResourceManager(string, ResourceManager)

Registers a resource manager from which the manager will retrieve resource strings.

public static void RegisterResourceManager(string resourceManagerName, ResourceManager resourceManager)

Parameters

resourceManagerName string

A name for the resource manager that can be used in markup to reference a particular set of resources. Normally the main application will pass null for this, and no resource manager will be specified in markup so that this resource manager will be checked first.

resourceManager ResourceManager

The resource manager.

Remarks

There may be more than one resource manager, since class libraries can contain resources as well. The main executable assembly should register its resource manager during initialization, and each class library that contains resources that will be referenced by this markup extension should register its resource manager during its initialization as well.