'Get font in use when multiple font families specified in WPF
In WPF I set a style for my control so it has multiple font families specified:
<Style TargetType="{x:Type MyControl}">
<Setter Property="FontFamily"
Value="Helvetica, Arial, Segoe UI" />
</Style>
How can I determine which font is actually got selected and is in use for the control?
Solution 1:[1]
I ended up just having to parse the FontFamily's Source property:
public static FontFamily GetFirstValid(this FontFamily fontFamily)
{
return fontFamily?.Source.Split(',')
.Select(p => new FontFamily(p))
.FirstOrDefault(f => f.GetTypefaces()
.Any(t => t.TryGetGlyphTypeface(out GlyphTypeface glyph)
&& glyph?.CharacterToGlyphMap.Count > 0));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | g t |
