从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法

原文:从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法

主程序 为 Main_Test.exe

被加载的DLL 为 Load_Test.dll  此DLL 中 有一个 文件夹Resources文件夹有一个资源字典Graphics.xaml

目的是为了加载Load_Test.dll 中的资源字典Graphics.xaml

方法一  用绝对路径 

System.Windows.ResourceDictionary rDic = new System.Windows.ResourceDictionary {
   Source = new Uri( "Pack://application:,,,/Load_Test;Component/Resources/Graphics.xaml",UriKind.Absolute);
};

注意 :,,, 是三个逗号

方法二 用相对路径

System.Windows.ResourceDictionary rDic = new System.Windows.ResourceDictionary { 
   Source = new Uri( @"/Load_Test;Component/Resources/Graphics.xaml",UriKind.Relative);
};

方法三 加载的方式

System.Windows.ResourceDictionary rDic =  System.Windows.Application.LoadComponent(new Uri( @"/Load_Test;Component/Resources/Graphics.xaml", UriKind.Relative)) as System.Windows.ResourceDictionary;

 

从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法