NoesisGUI

LocExtension Class

namespace Noesis

Implements a markup extension that supports references to a localization ResourceDictionary.

Provides a value for any XAML property attribute by looking up a reference in the ResourceDictionary defined by the Source attached property. Values will be re-evaluated when the Source attached property changes.

If used with a string or object property, and the provided resource key is not found, the LocExtension will return a string in the format "<Loc !%s>" where %s is replaced with the key.

This example shows the full setup for a LocExtension. It utilizes the RichText attached property to support BBCode markup in the localized strings. The Loc.Source property references the "Language_en-gb.xaml" ResourceDictionary below.

<StackPanel
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions"
  noesis:Loc.Source="Language_en-gb.xaml">
  <Image Source="{noesis:Loc Flag}"/>
  <TextBlock noesis:RichText.Text="{noesis:Loc TitleLabel}"/>
  <TextBlock noesis:RichText.Text="{noesis:Loc SoundLabel}"/>
</StackPanel>

This is the contents of a "Language_en-gb.xaml" localized ResourceDictionary:

Language_en-gb.xaml
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <ImageBrush x:Key="Flag" ImageSource="Flag_en-gb.png" Stretch="Fill"/>
  <sys:String x:Key="TitleLabel">[b]LOCALIZATION SAMPLE[/b]</sys:String>
  <sys:String x:Key="SoundLabel">A [i]sound[/i] label</sys:String>
</ResourceDictionary>

Inheritance Hierarchy

LocExtension

INDEX Class Hierarchy Index

Properties


Name Description
None ResourceKey Gets or sets the value of the key to use when finding a resource

DP_ Dependency Property      RO_ Read-only


Methods

Name Description
GetResources Gets or sets the value of the key to use when finding a resource
GetSource Gets the value of the Source property of for the localization dictionary
IsResourcesProperty Gets or sets the value of the key to use when finding a resource
SetSource Sets the value of the Source property of for the localization dictionary

From MarkupExtension

Name Description
ProvideValue Returns an object that is provided as the value of the target property for this extension

Events

LocExtension has no events

© 2017 Noesis Technologies