Edit

Share via


BamlLocalizableResourceKey Class

Definition

Represents a key that is used to identify localizable resources in a BamlLocalizationDictionary.

public ref class BamlLocalizableResourceKey
public class BamlLocalizableResourceKey
type BamlLocalizableResourceKey = class
Public Class BamlLocalizableResourceKey
Inheritance
BamlLocalizableResourceKey

Examples

The following example demonstrates how to use a BamlLocalizableResourceKey.


// Obtain the BAML stream.
Stream source = entry.Value as Stream;

// Create a BamlLocalizer on the stream.
BamlLocalizer localizer = new BamlLocalizer(source);
BamlLocalizationDictionary resources = localizer.ExtractResources();

// Write out all the localizable resources in the BAML.
foreach (DictionaryEntry resourceEntry in resources)
{
    BamlLocalizableResourceKey key = resourceEntry.Key as BamlLocalizableResourceKey;
    BamlLocalizableResource value = resourceEntry.Value as BamlLocalizableResource;
    Console.WriteLine(
        "    {0}.{1}.{2} = {3}",
        key.Uid,
        key.ClassName,
        key.PropertyName,
        value.Content
        );                                
}

' Obtain the BAML stream.
Dim source As Stream = TryCast(entry.Value, Stream)

' Create a BamlLocalizer on the stream.
Dim localizer As New BamlLocalizer(source)
Dim resources As BamlLocalizationDictionary = localizer.ExtractResources()

' Write out all the localizable resources in the BAML.
For Each resourceEntry As DictionaryEntry In resources
    Dim key As BamlLocalizableResourceKey = TryCast(resourceEntry.Key, BamlLocalizableResourceKey)
    Dim value As BamlLocalizableResource = TryCast(resourceEntry.Value, BamlLocalizableResource)
    Console.WriteLine("    {0}.{1}.{2} = {3}", key.Uid, key.ClassName, key.PropertyName, value.Content)
Next resourceEntry

Remarks

This class represents a key that can uniquely identify a localizable value inside binary XAML (BAML). It represents a combination of a Uid, class name, and property name.

The Uid value must be added to the source Extensible Application Markup Language (XAML) file either by using the updateuid Microsoft build engine (MSBuild) target (for example, msbuild /t:updateuid myproj.proj), or manually in the markup. BAML without a Uid cannot be localized. The class name is the type name of the element that contains the localizable property. The property name refers to the property that has the localizable value. A special property called "$Content" is used to represent values that are the initialization text or content property of an element. For example the $Content property name would apply to the initialization text Click in the following XAML:

<TextBlock x:Uid="myBlock">Click </TextBlock>

Constructors

BamlLocalizableResourceKey(String, String, String)

Initializes a new instance of the BamlLocalizableResourceKey class with the supplied Uid, class name, and property name.

Properties

AssemblyName

Gets the name of the assembly that defines the type of the localizable resource as declared by its ClassName.

ClassName

Gets the class name component of this BamlLocalizableResourceKey.

PropertyName

Gets the property name component of this BamlLocalizableResourceKey.

Uid

Gets the Uid component of this BamlLocalizableResourceKey.

Methods

Equals(BamlLocalizableResourceKey)

Compares two instances of BamlLocalizableResourceKey for equality.

Equals(Object)

Compares an object to an instance of BamlLocalizableResourceKey for equality.

GetHashCode()

Returns an integer hash code representing this instance.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also