2012-03-14 61 views
4

我使用msdn tutorial在我的WPF应用程序中添加的FontFamily,在.csproj的我:添加字体系列中的ResourceDictionary

<ItemGroup> 
    <Resource Include="Resources\MetaOT-Norm.otf" /> 
    <Resource Include="Resources\MetaOT-Bold.otf" /> 
    </ItemGroup> 

我加了fontFamily中的ResourceDictionary中,这样的:

<FontFamily x:Key="FontMetaOT">./Resources/#Meta OT</FontFamily> 

但它没有被应用......(我尝试过使用windows Fonts目录中的字体文件,它工作的很好)。任何想法 ?

+0

是否有OpenType字体有问题? – 2012-03-14 17:03:11

+0

@ahmet你是什么意思?有效地,我没有找到任何使用.otf扩展名的示例,其中大多数使用.ttf扩展名...您认为我可以在此代码中使用.otf扩展名吗? – rad 2012-03-14 17:30:52

+0

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

回答

2

如果您使用资源字典文件,则必须使用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> 
+1

但是我必须在哪里使用这个,在FontFamily Tag或Resource内部,看到一个完整的例子会很好。 – CularBytes 2016-03-10 11:36:28