如果您使用资源字典文件,则必须使用包 URI 方案 https://msdn.microsoft.com/library/aa970069(v=vs.100).aspx。
例如:
以下示例显示了 XAML 资源文件的包 URI
位于引用程序集的项目文件夹的根目录中。
pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml
以下示例显示了 XAML 资源文件的包 URI
位于引用程序集的项目文件夹的子文件夹中。
pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml
以下示例显示了 XAML 资源文件的包 URI
位于引用的、特定于版本的根文件夹中
程序集的项目文件夹。
pack://application:,,,/ReferencedAssembly;v1.0.0.1;component/ResourceFile.xaml
如果文件位于输出文件夹中,您可以使用原始站点来引用它:
以下示例显示 XAML 源站点的包 URI
文件,存储在可执行程序集所在的位置
推出。
pack://siteoforigin:,,,/SiteOfOriginFile.xaml
以下示例显示 XAML 源站点的包 URI
文件,存储在相对于其所在位置的子文件夹中
应用程序的可执行程序集启动。
pack://siteoforigin:,,,/Subfolder/SiteOfOriginFile.xaml
举个例子:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--A resource dictionary in the output folder in the Assets folder-->
<ResourceDictionary Source="pack://siteoforigin:,,,/Assets/OpenIconsDictionary.xaml"/>
<!--A resource dictionary packed in the Gui dll-->
<ResourceDictionary Source="pack://application:,,,/Gui;component/Assets/PackedIconsDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<!--In the output folder /Assets/OpenIconsDictionary.xaml (Build Action: Embedded Resource, Copy always)-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="Icon"
UriSource="pack://siteoforigin:,,,/Images/image.png"/>
</ResourceDictionary>
<!--In Gui.dll in the folder /Assets/PackedIconsDictionary.xaml (Build Action: Page, Do not copy)-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="Icon"
UriSource="pack://siteoforigin:,,,/Images/image.png"/>
</ResourceDictionary>