Can Visual Studio XAML designer handle font family names with spaces as a resource?
Asked Answered
C

1

2

This probably seems like a strange question, but I'm having trouble seeing a custom true-type font that I've loaded as a resource in my WPF application, and I'm wondering if it may have to do with the space in the font name.

As described elsewhere (one of hundreds of examples), I've added the font to a folder Fonts in my application, and set it to Build Action = Resource. I'm able to reference the font (e.g., in a TextBlock) with a simple FontFamily="Fonts\#My Font".

Unfortunately, the font only shows up at run time, not in the XAML designer (contrary to most people's problems). However, as explained here, this author had a similar problem with the font Open Sans, and if I install the font on my system, as he did, I can see it at design time.

But I'd rather not force developers to install the font on their system. I noticed that, like the author above, I don't have this problem with a few custom fonts that have names without spaces. So I'm wonder if this is perhaps a bug in Visual Studio (I'm using Community 2013). Has anyone been able to get this to work with a font whose name contains a space? Or has anyone found a more satisfying workaround (e.g., way to reference the font without the space akin to Windows short files names)?

Cumings answered 22/9, 2015 at 17:40 Comment(0)
A
1

I had this very same problem. The solution is taking out the spaces, although you can't just edit the file name. Here's how I did it:

  • Download FontForge - http://fontforge.github.io/en-US/.
  • Open the font file
  • Go to Elements -> Font Info
  • In there look for xyz Names, mine was TTF Names due to it being Wingdings
  • Edit them to remove the spaces, I'm pretty sure the only one that matters is the "UniqueID" but I did them all.
  • Go to File -> Generate Fonts and save the font as the proper type.
  • Re-add the file and reference the font without spaces

This was the only way I could get it to work but it ended up working without a hitch. Best of luck.

Apologete answered 29/9, 2015 at 9:52 Comment(1)
Thank you! For the font I was using - PT Sans - I only had to edit the "PS Name"->"Family Name", as the "TTF Names" were attached (linked) to the PS (Postscript) Names. I chose to put underscores instead of spaces, which also worked. Grr to the Microsoft Visual Studio team. I tried to submit feedback but their bug reporting system appears to be down.Cumings

© 2022 - 2024 — McMap. All rights reserved.