Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Embedded fonts in styles at runtime

$
0
0

This is kind of a re-post, and I apologize for that, but in doing a repro, I realized I hadn't described the problem accurately, and I only got one (well-meant, but irrelevant) response to my original. And not finding a solution to this will be a very.bad.thing...

So, the problem is that when I have two stylesheets, one that defines the styles, and second that sets them as implicit, the embedded font is displayed correctly in the designer, but not at runtime.

Steps to Repro:

  1. Add an embedded font to your project (I used BuxtonSketch)
  2. Create a basic ResourceDictionary file (mine is called PoCDefaults.xaml) that declares the font as a resource and contains a style that references the resource:

    <SolidColorBrush x:Key="BaseForeground-Sketch" Color="#FF606060"/>
    <FontFamily x:Key="FontFamily-Sketch">Fonts/#Buxton Sketch</FontFamily>

    <!-- Basic Sketch TextBlock -->
    <Style x:Key="TextBlock-PoC" TargetType="{x:Type TextBlock}">
    <Setter Property="FontFamily" Value="{DynamicResource FontFamily-Sketch}"/>
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Foreground" Value="{DynamicResource BaseForeground-Sketch}"/> </Style>
  3. Add a second ResourceDictionary that sets the TextBlock-PoC as the default for TextBlock controls:

    <Style TargetType="{x:Type TextBlock}" BasedOn="{Static Resource TextBlock-PoC}" />
  4. Reference both files in a MergedDictionary in App.xaml.
  5. Add a TextBlock to MainWindow. It displays correctly in the designer:

But not at runtime:



Rebecca M. Riordan


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>