Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need any markup extensions to accomplish this. You can do it with a simple ValueConverter.</p> <ol> <li><p>Add .resx file to your project (for this example we will call it Resource1.resx, with a string value named "String1" value "Hello world!")</p></li> <li><p>Create a converter that will convert a string to a localized string.</p> <pre><code>namespace WpfApplication1.Converters { public class ResxLocalizationConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string result = Resource1.ResourceManager.GetString(value.ToString()); if (result == null) { result = value.ToString(); } return result; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } </code></pre></li> <li><p>Add a converter instance to App.xaml</p> <pre><code>&lt;Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml" xmlns:converters="clr-namespace:WpfApplication1.Converters"&gt; &lt;Application.Resources&gt; &lt;converters:ResxLocalizationConverter x:Key="ResxLocalizationConverter" /&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre></li> <li><p>Put the non-localized string values (or keys) in your XAML.</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;TextBlock Text="{Binding Source='String1', Converter={StaticResource ResxLocalizationConverter}}"/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre></li> </ol> <p>This will display "Hello world!" in the TextBlock.</p> <p>To localize for French, for example, you would just need to add Resource1.fr-FR.resx to the Visual Studio project (with a string value named "String1" value "Salut tout le monde!"). This will display the French version on French localized PCs, or you can use the ResourceManager.GetString(...) overload that lets you explicitly select the language.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload