WPF - copy/paste selection with custom font family

Posted by summergoat on Stack Overflow See other posts from Stack Overflow or by summergoat
Published on 2010-04-14T18:02:00Z Indexed on 2010/04/14 18:03 UTC
Read the original article Hit count: 226

Filed under:
|
|

I have a custom font family embedded in my WPF application which I can reference by specifying a base URI and font family name.

new FontFamily(new Uri("pack://application:,,,/Fonts/"), "./#My Custom Font Family");

However, when I copy a selection which uses this font the xaml on the clipboard resembles the following

<Run Text="Foo" FontFamily="./#My Custom Font Family" />

When I paste into the same RichTextBox I lose the font as it falls back to the system default because -

When a FontFamily is specified as an attribute in markup, the base URI value is always implied—its value is the URI of the XAML page. http://msdn.microsoft.com/en-us/library/system.windows.media.fontfamily.aspx

and my xaml page is not located in the same directory as the custom font family.

Any ideas for a workaround?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about fonts