Using a font resource from another assembly

I currently have a class library project that contains themes / templates and fonts (as resources). Then I refer to this project called Shared.UI in my main WPF application project.

I reference it using:

<ResourceDictionary Source="pack://application:,,,/Shared.UI;component/Skin.xaml" /> 

in the MergedDictionary tag.

The problem I encountered is that the main WPF application cannot use the fonts from the project where they are created as resources.

In my Shared.UI / Skins.xaml file, I have:

 <!-- 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> 

I assume that this does not work in my main WPF application because it looks in its own ./resources for #Helvetica Neue and does not find it (because it is in Shared.UI). I also tried explicitly referencing /Shared.UI;component/resources/#Helvetica Neue in the resource file, but this did not work for me.

+4
source share
1 answer

Check out this link, hope it helps http://social.msdn.microsoft.com/Forums/vstudio/en-US/068d9600-93e6-45e4-af37-2b04e4b41855/how-to-load-a-font-from -a-resource-only-dll-in-c

 <TextBlock><Run FontFamily="/FontClassLibrary;Component/#YourFontName" FontSize="20">Your Text</Run></TextBlock> 
+1
source

Source: https://habr.com/ru/post/1490571/


All Articles