嗨,我需要制作多语言 WPF 办公插件。我想使用资源文件。我在我的 ThisAddIn_Startup 函数中调用我的 SetLanguageDictionary
public static void SetLanguageDictionary()
{
try
{
//Get the assembly information
System.Reflection.Assembly assemblyInfo = System.Reflection.Assembly.GetExecutingAssembly();
Uri uriCodeBase = new Uri(assemblyInfo.CodeBase);
string path = Path.GetDirectoryName(uriCodeBase.LocalPath.ToString());
ResourceDictionary dict = new ResourceDictionary();
switch (Thread.CurrentThread.CurrentCulture.ToString())
{
case "en-US":
dict.Source = new Uri(path + "\\Resources\\en-US.xaml",
UriKind.Absolute);
break;
case "fr-FR":
dict.Source = new Uri(path + "\\Resources\\fr-FR.xaml",
UriKind.Absolute);
break;
default:
dict.Source = new Uri(path + "\\Resources\\en-US.xaml",
UriKind.Absolute);
break;
}
Application.Current.Resources.MergedDictionaries.Add(dict);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
我的资源文件在那里
<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">
<system:String x:Key="Ready">Ready</system:String>
<system:String x:Key="login">Login</system:String>
<!-- All StringResources Goes Here -->
</ResourceDictionary>
加载时出现错误:系统无效操作异常:操作错误 loadfrom resouceDictionary with URI:"file:///c:
感谢您的回复