2012-05-19

Articles

Translation

 

In XAML files you can dynamic load string by using the DynamicResource. This doesn't exist in C#, therefore you need your own method for loading a string by the key. This object helps you doing this.

 

 

Usage

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:System="clr-namespace:System;assembly=mscorlib">

	<System:String x:Key="Demo_Welcome">Welcome to the demo</System:String>
	
</ResourceDictionary>
<UserControl x:Class="DW.SharpTools.Demo.TranslationControl"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 mc:Ignorable="d" 
			 d:DesignHeight="300" d:DesignWidth="300">
	<StackPanel HorizontalAlignment="Center">
		<Button Content="Show" Click="ShowWelcomeText" />
	</StackPanel>
</UserControl>
using System.Windows;
using System.Windows.Controls;

namespace DW.SharpTools.Demo
{
	public partial class TranslationControl : UserControl
	{
		public TranslationControl()
		{
			InitializeComponent();
		}

		private void ShowWelcomeText(object sender, RoutedEventArgs e)
		{
			MessageBox.Show(Translation.Load("Demo_Welcome"));
		}
	}
}