using System;
using System.Configuration;
using System.Windows;
using System.Windows.Controls;

public class ResourceManager
{
    //public static void SwitchLanguage(string culture)
    //{
    //    var uri = new Uri($"/Resources/Strings.{culture}.xaml", UriKind.Relative);
    //    var resourceDict = Application.LoadComponent(uri) as ResourceDictionary;

    //    Application.Current.Resources.MergedDictionaries.Clear();
    //    Application.Current.Resources.MergedDictionaries.Add(resourceDict);
    //}

    public static void SwitchLanguage(string culture)
    {
        try
        {
            // 保存到App.config
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings["Language"].Value = culture;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

            // 切换语言
            var resourceDict = new ResourceDictionary
            {
                Source = new Uri($"/Resources/Strings.{culture}.xaml", UriKind.Relative)
            };

            Application.Current.Resources.MergedDictionaries.Clear();
            Application.Current.Resources.MergedDictionaries.Add(resourceDict);
        }
        catch (Exception ex)
        {
            MessageBox.Show($"切换语言失败: {ex.Message}");
        }
    }
}

// 在SelectionChanged中使用


