如果您使用資源字典文件,則必須使用Pack URI Scheme來解決這些文件。 例如:
下面的示例顯示 位於引用的程序集的項目文件夾的根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
如果該文件位於輸出文件夾,您可以使用源站點引用它:
下面的示例演示包URI原產 的XAML網站文件,存儲在可執行程序集從其中啓動的位置 。
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>
是否有OpenType字體有問題? – 2012-03-14 17:03:11
@ahmet你是什麼意思?有效地,我沒有找到任何使用.otf擴展名的示例,其中大多數使用.ttf擴展名...您認爲我可以在此代碼中使用.otf擴展名嗎? – rad 2012-03-14 17:30:52
Silverlight支持OTF。你有沒有試過直接參考?像這樣:http://blogs.silverlight.net/blogs/msnow/archive/2008/09/25/silverlight-tip-of-the-day-46-font-support-in-silverlight.aspx – Jeremiah 2012-03-14 17:47:33