0
votes

I have dll It my custom control. I need to use font in dll from resources from the app.

I wrote code but it working if font installed on PC.

new Typeface(new FontFamily(new Uri("pack://application:,,,/Astro;Component/Fonts")

How to solve it problem? I need use font without install on PC.

1

1 Answers

0
votes

If you encapsulate the custom control inside it's own assembly, you shouldn't have a reference to the applications assembly from there. Embed the font files as resources inside your custom control project or define a distinct styling project which is then referenced from your custom control and your application as well.

project

You can then define and use XAML font families as resources as shown below. The XAML is placed inside Fonts.xaml which is located in the same folder as the font files:

<FontFamily x:Key="ColaborateThin">./#Colaborate Thin</FontFamily>
<FontFamily x:Key="ColaborateRegular">./#Colaborate Regular</FontFamily>
<FontFamily x:Key="ColaborateBold">./#Colaborate Bold</FontFamily>
<FontFamily x:Key="DroidSansRegular">./#Droid Sans Regular</FontFamily>
<FontFamily x:Key="SegoeRegular">Segoe</FontFamily>

<Style x:Key="H1">
    <Setter Property="TextElement.FontFamily" Value="{StaticResource ColaborateThin}" />
    <Setter Property="TextElement.FontSize" Value="21px" />
    <Setter Property ="TextElement.Foreground" Value="{StaticResource PrimaryBrush}" />
</Style>