如何使用mvvm从wpf中的ResourceDictionary访问键值

如何使用mvvm从wpf中的ResourceDictionary访问键值,wpf,mvvm,Wpf,Mvvm,我已经在WPF-MVVM应用程序的资源文件夹下创建了Resource.fr-CA.xaml、Resource.en-US.xaml文件 我创建了Resource.fr-CA.xaml和Resource.en-US.xaml文件,如下所示: Resource.fr-CA.xaml <system:String x:Key="EntUser_PhoneNo_Label">Num\u00e9ro de t\u00e9l\u00e9phone</system:String>

我已经在WPF-MVVM应用程序的资源文件夹下创建了Resource.fr-CA.xaml、Resource.en-US.xaml文件

我创建了Resource.fr-CA.xaml和Resource.en-US.xaml文件,如下所示:

Resource.fr-CA.xaml

<system:String x:Key="EntUser_PhoneNo_Label">Num\u00e9ro de t\u00e9l\u00e9phone</system:String>   
<system:String x:Key="EntUser_PhoneNo_Label">Phone Number</system:String>    

Num\u00e9ro de t\u00e9l\u00e9phone

Resource.en-US.xaml

<system:String x:Key="EntUser_PhoneNo_Label">Num\u00e9ro de t\u00e9l\u00e9phone</system:String>   
<system:String x:Key="EntUser_PhoneNo_Label">Phone Number</system:String>    

电话号码

我的应用程序包含一个组合框,用于选择不同类型的语言

如果用户选择法语,则我必须从Reource.fr CA获取EntUser\u PhoneNo\u Label键值,或者如果用户选择英语语言,则我必须从Resource.en US.xaml获取值


请告诉我如何从相应的.xaml文件的ResourceDictionary中从代码隐藏中获取key/value的解决方案。

此代码运行良好:

   byte[] utf8String = Encoding.UTF8.GetBytes("Num\u00e9ro de t\u00e9l\u00e9phone"); 
   string str1 = Encoding.UTF8.GetString(utf8String);
这也是:

public static class  StringDecoder
    {
        public static string Decode(string str)
        {
            if (str == null)
            {
                return null;
            }
            return HttpUtility.UrlDecode(str, Encoding.UTF8);
        }

    }
var str = StringDecoder.Decode("Num\u00e9ro de t\u00e9l\u00e9phone"); // returns Numéro de téléphone

大家好,我可以按如下方式访问键值:ResourceDictionary MyResDict=new ResourceDictionary();MyResDict.Source=newURI(“/MyLang;component/Resources/Resource.fr-CA.xaml”,UriKind.RelativeOrAbsolute);byte[]utf8String=Encoding.UTF8.GetBytes(Convert.ToString(MyResDict[“LoginButton_Label]”));string str1=Encoding.UTF8.GetString(utf8String);EntUser\u PhoneNo\u Label=str1;但这里我的问题是我无法将“Num\u00e9ro de t\u00e9l\u00e9phone”转换为“Numéro de téléphone”