![](https://i-blog.csdnimg.cn/direct/294fc42a94444bb4bc85267a0db36c38.png)
![](https://i-blog.csdnimg.cn/direct/8fee9b0323dc4b069cda7ae873894c1f.png)
![](https://i-blog.csdnimg.cn/direct/736df5cc79654b92adb5fcdd0fb0a6f4.png)
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="en-us.xaml" />
<ResourceDictionary Source="zh-cn.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
![](https://i-blog.csdnimg.cn/direct/094d7e9f82134577b723c34a2b299ef3.png)
public static void UpdateLanguage(string lan)
{
// 获取配置
string requestedLanguage = $"{lan}.xaml";
ResourceDictionary resourceDictionary = Application.Current.Resources.MergedDictionaries.FirstOrDefault(d => d.Source.OriginalString.Equals(requestedLanguage));
Current.Resources.MergedDictionaries.Remove(resourceDictionary);
Current.Resources.MergedDictionaries.Add(resourceDictionary);
// 保存配置
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationManager.AppSettings["Language"] = lan;
config.Save(ConfigurationSaveMode.Modified);
//刷新
ConfigurationManager.RefreshSection("appSettings");
}
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<!--<TextBlock Text="用户名:" Margin="0,5,0,0"/>-->
<TextBlock Text="{DynamicResource Username}" Margin="0,5,0,0"/>
<TextBox x:Name="txtUsername" Width="200" Height="30" Margin="0,0,15,0"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{DynamicResource Password}" Margin="0,5,0,0"/>
<PasswordBox x:Name="txtPassword" Width="200" Height="30" Margin="0,0,15,0"/>
</StackPanel>
<StackPanel Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="{DynamicResource Login}" Background="#0047AB" Foreground="White" HorizontalAlignment="Right" Click="LoginButton_Click" Width="200" Height="30" Margin="30,0,0,0"/>
</StackPanel>
private void LanguageSwitching(object sender, RoutedEventArgs e)
{
App.UpdateLanguage("en-us");
}
![](https://i-blog.csdnimg.cn/direct/95aa18caf0e74ffaac48b88fd25b5a04.png)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String x:Key="OK">Sure</s:String>
<s:String x:Key="Cancle">NoSure</s:String>
<s:String x:Key="Username">UserName:</s:String>
<s:String x:Key="Password">PassWord:</s:String>
<s:String x:Key="Login">Login</s:String>
<s:String x:Key="LanS">简体中文</s:String>
</ResourceDictionary>
![](https://i-blog.csdnimg.cn/direct/73f5ee2ab52f4f92a6f6ce5a221601d0.png)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String x:Key="OK">确认</s:String>
<s:String x:Key="Cancle">取消</s:String>
<s:String x:Key="Username">用户名:</s:String>
<s:String x:Key="Password">密码:</s:String>
<s:String x:Key="Login">登录</s:String>
<s:String x:Key="LanS">English</s:String>
</ResourceDictionary>