Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you created two ResourceDictionary files you can binding by <code>DynamicResource</code>.</p> <p>Example:</p> <p>First resource file (Lang.en-US.xaml):</p> <pre><code>&lt;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"&gt; &lt;system:String x:Key="Username"&gt;Username:&lt;/system:String&gt; &lt;system:String x:Key="Password"&gt;Password:&lt;/system:String&gt; &lt;system:String x:Key="close"&gt;Close&lt;/system:String&gt; &lt;system:String x:Key="login"&gt;Login&lt;/system:String&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>Second resource file (Lang.pl-PL.xaml):</p> <pre><code>&lt;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"&gt; &lt;system:String x:Key="Username"&gt;Login:&lt;/system:String&gt; &lt;system:String x:Key="Password"&gt;Hasło:&lt;/system:String&gt; &lt;system:String x:Key="close"&gt;Zamknij&lt;/system:String&gt; &lt;system:String x:Key="login"&gt;Zaloguj&lt;/system:String&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>Set default language in Application resources:</p> <pre><code> &lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="Lang.en-US.xaml" /&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; </code></pre> <p>Let's say that we have ComboBox like below:</p> <pre><code>&lt;ComboBox Name="cbLang" Margin="2" SelectionChanged="cbLang_SelectionChanged" &gt; &lt;ComboBoxItem Content="English" Tag="en-US" /&gt; &lt;ComboBoxItem Content="Polish" Tag="pl-PL" /&gt; &lt;/ComboBox&gt; </code></pre> <p>Code-behind SelectionChanged:</p> <pre><code> private void cbLang_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { ResourceDictionary dict = new ResourceDictionary(); switch (((sender as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString()) { case "en-US": dict.Source = new Uri("Lang.en-US.xaml", UriKind.Relative); break; case "pl-PL": dict.Source = new Uri("Lang.pl-PL.xaml", UriKind.Relative); break; default: break; } this.Resources.MergedDictionaries.Add(dict); } </code></pre> <p>And you can binding like this:</p> <pre><code> &lt;TextBlock Text="{DynamicResource Username}" VerticalAlignment="Center" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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