我使用wpf处理应用程序,它适用于多种语言。用户可以将语言dll放在Languages文件夹中,程序动态加载它们。我想用它显示国家标志的程序集名称。我写了这个代码,但flage图像没有显示在组合框中。我怎么能这样做?
var assemblies = dir.GetFiles("*.dll", SearchOption.AllDirectories);
//for each found .dll we will create a model and set its properties and then add to list
for (int i = 0; i < assemblies.Count(); i++)
{
var assemblyName = assemblies[i].Name.Substring(0, assemblies[i].Name.LastIndexOf("."));
string packUri = string.Format("pack://application:,,,/{0};component/Image/flag.png", assemblyName);
Uri uri = new Uri(packUri, UriKind.Absolute);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
try
{
image.UriSource = uri;
image.EndInit();
}
catch (Exception ex)
{
var m = ex.Message;
}
CultureAssemblyModel model = new CultureAssemblyModel()
{
DisplayText = assemblies[i].Name.Split('.', '_')[2],
Culture = assemblies[i].Name.Split('.', '_')[1],
Name = assemblies[i].Name,
XamlFileName = assemblies[i].Name.Substring(0, assemblies[i].Name.LastIndexOf(".")) + ".xaml",FlagImage=image
};
答案 0 :(得分:0)
我可能会尝试将MEF用于此类事情。
我会允许你:
这可能会在加载部分上大大简化,但在dll创建部分它当然有点复杂。