title: How to change UI language using resource dictionary at run time?
body: <p>I want to change my project language by button_click event, so I use ResourceDictionary to do it like this:</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>    &lt;Button Content="{DynamicResource LanguageSetting}" Click="btn_LanguageSetting_Click"/&gt;
  </code></pre>
  
  <p><strong>Code Behind</strong></p>
  
  <pre><code>    public static string windowCurrentLanguageFile = "Language/en.xaml";
      private void btn_LanguageSetting_Click(object sender, RoutedEventArgs e)
      {
          windowCurrentLanguageFile = windowCurrentLanguageFile == "Language/en.xaml"
              ? "Language/fr.xaml"
              : "Language/en.xaml";
  
          var rd = new ResourceDictionary() { Source = new Uri(windowCurrentLanguageFile, UriKind.RelativeOrAbsolute) };
  
          if (this.Resources.MergedDictionaries.Count == 0)
              this.Resources.MergedDictionaries.Add(rd);
          else
              this.Resources.MergedDictionaries[0] = rd;
      }
  </code></pre>
  
  <p>This works fine for the xaml file, but I also want to change my viewmodel's language in the code behind.</p>
  
  <p><strong>My ItemsControl in the xaml:</strong> </p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding ItemOperate}"&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate DataType="{x:Type viewmodel:SelectableViewModel}"&gt;
                  &lt;Border x:Name="Border" Padding="0,8,0,8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}"&gt;
                      &lt;Grid&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition SharedSizeGroup="Checkerz" /&gt;
                              &lt;ColumnDefinition /&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;ToggleButton VerticalAlignment="Center" IsChecked="{Binding IsSelected}"
                                        Style="{StaticResource MaterialDesignActionLightToggleButton}"
                                        Content="{Binding Code}" /&gt;
                          &lt;StackPanel Margin="8 0 0 0" Grid.Column="7"&gt;
                              &lt;TextBlock FontWeight="Bold" Text="{Binding Name}" /&gt;
                              &lt;TextBlock Text="{Binding Description}" /&gt;
                          &lt;/StackPanel&gt;
                      &lt;/Grid&gt;
                  &lt;/Border&gt;
                  &lt;DataTemplate.Triggers&gt;
                      &lt;DataTrigger Binding="{Binding IsSelected}" Value="True"&gt;
                          &lt;Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" /&gt;
                      &lt;/DataTrigger&gt;
                  &lt;/DataTemplate.Triggers&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>Which Binding to the <strong>ViewModel</strong> like this:</p>
  
  <pre><code>public class SelectableViewModel : INotifyPropertyChanged
  { 
      public event PropertyChangedEventHandler PropertyChanged;
      protected virtual void OnPropertyChanged(string propertyName = null)
      {
          var handler = PropertyChanged;
          if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
      }
  
      private bool _isSelected;
      public bool IsSelected
      {
          get { return _isSelected; }
          set
          {
              if (_isSelected == value) return;
              _isSelected = value;
              OnPropertyChanged();
          }
      }
  
      private char _code;
      public char Code
      {
          get { return _code; }
          set
          {
              if (_code == value) return;
              _code = value;
              OnPropertyChanged();
          }
      }
  
      private string _name;
      public string Name
      {
          get { return _name; }
          set
          {
              if (_name == value) return;
              _name = value;
              OnPropertyChanged();
          }
      }
  
      private string _description;
      public string Description
      {
          get { return _description; }
          set
          {
              if (_description == value) return;
              _description = value;
              OnPropertyChanged();
          }
      }
  }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>    public MainViewModel()
      {
          _itemOperate = CreateData();
      }
  
      private static ObservableCollection&lt;SelectableViewModel&gt; CreateData()
      {
          return new ObservableCollection&lt;SelectableViewModel&gt;
              {
                  new SelectableViewModel
                  {
                      Code = 'E', 
                      Name = "Erase",
                      Description = "Erase The MCU Chip By Page"
                  },
                  new SelectableViewModel
                  {
                      Code = 'D',
                      Name = "Detect",
                      Description = "Detect The MCU Flash",
                  },
                  new SelectableViewModel
                  {
                      Code = 'P',
                      Name = "Programming",
                      Description = "Programming The MCU Chip By Hex File",
                  },
                  new SelectableViewModel
                  {
                      Code = 'V',
                      Name = "Verify",
                      Description = "Verify The Downing Code",
                  },
                  new SelectableViewModel
                  {
                      Code ='L',
                      Name = "Lock",
                      Description = "Lock The Code To Protect The MCU",
                  }
              };
      }
  </code></pre>
  
  <p>So how I suppose to change the language my model SelectableViewModel <code>Code</code>, <code>Name</code>, <code>Description</code> instead of using this hard code? Thanks!</p>