使用其他程序集中的字体资源

jya*_*nks 5 wpf resources fonts label resourcedictionary

目前,我有一个包含主题/模板和字体(作为资源)的类库项目.然后我在我的主WPF应用程序项目中引用名为Shared.UI的项目.

我使用以下方法引用它:

<ResourceDictionary Source="pack://application:,,,/Shared.UI;component/Skin.xaml" />
Run Code Online (Sandbox Code Playgroud)

在MergedDictionary标记内.

我遇到的问题是主WPF应用程序无法使用项目中的字体作为资源构建.

在我的Shared.UI/Skins.xaml文件中,我有:

<!-- LABEL -->
<Style TargetType="{x:Type Label}">
    <Setter Property="FontFamily" Value="./resources/#Helvetica Neue" />
    <Setter Property="Foreground" Value="{DynamicResource PrimaryBlue}" />
    <Setter Property="FontSize" Value="12" />
</Style>
Run Code Online (Sandbox Code Playgroud)

我假设这在我的主WPF应用程序中不起作用,因为它自己./resources查找#Helvetica Neue并且找不到它(因为它在Shared.UI中).我试图/Shared.UI;component/resources/#Helvetica Neue在资源文件中明确引用,但这对我不起作用.

Nit*_*esh 2

检查此链接,希望它有帮助 http://social.msdn.microsoft.com/Forums/vstudio/en-US/068d9600-93e6-45e4-af37-2b04e4b41855/how-to-load-a-font-from-a -c 中的仅资源 dll

<TextBlock><Run FontFamily="/FontClassLibrary;Component/#YourFontName" FontSize="20">Your Text</Run></TextBlock>
Run Code Online (Sandbox Code Playgroud)

  • 虽然这从理论上可以回答这个问题,但[最好](​​http://meta.stackexchange.com/q/8259)在此处包含答案的基本部分,并提供参考链接。这样,即使链接失效,您的答案仍然有用。您还需要解释***如何***回答这个问题以及为什么它会解决这个问题。 (2认同)