3

I found some font type not able to using in UWP.

For example: Noto Sans CJK TC, or Noto Sans(both are Google opensource font)

Even this font already installed in system, or put into app project and using "ms-appx:" or relative path to setting this font.

(Like this question's answer:UWP - Font only applied in Designer, which provide a example, able to using custom font)

When I applied some font, only seen effect in designer but not in run-time.

And there have guideline but which didn't tell how to know which font type isn't able to using in UWP. https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/fonts?f=255&MSPPError=-2147217396

Is there have any font type limit in UWP?

Thanks!

Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • Try uninstalling the app and removing the obj, bin files and try installing it back again. I had the problem once. – AbsoluteSith May 11 '16 at 11:10
  • How you use these fonts in your code? Could you share your code? As in my test both Noto Sans and Noto Sans CJK TC font works well. – Jay Zuo May 12 '16 at 06:00
  • @JayZuo-MSFT I found the problem cause I put page inside folder, but why?... I upload example to bitbucket, change MainPage to UI.BlankPage1 in App.cs, you will see same XAML but UI.BlankPage1 won't apply any font change [Example on Bitbucket](https://bitbucket.org/thkaw/uwpfonttest) – Nathaniel Chen May 12 '16 at 13:40
  • And FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC" can work, but FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC Thin" won't. Noto Sans CJK TC Thin is FontType name which selected by Visual Studio property window, but it won't work. – Nathaniel Chen May 12 '16 at 13:44
  • I think there may have some problem in my visual studio, my friend help me test this problem by using example which I provide on BitBucket. And result is both page apply font without problem... – Nathaniel Chen May 12 '16 at 15:25
  • I also try to reference other project font resource in same solution, and UI/BlankPage only use this method that font can be change... that is weird ... I'm trying rebuild another environment to test. – Nathaniel Chen May 12 '16 at 15:29
  • I try fresh install W10 Insider preview and Visual Studio 2015 update. But no luck... 2 Windows 10 10586+ 1 Windows 10 Insider preview both are not able to apply font on UI/BlankPage.xaml :( – Nathaniel Chen May 13 '16 at 02:18

1 Answers1

6

I found the problem cause I put page inside folder, but why?

In you code, you are using following code to set FontFamily:

FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"

The URI you've used is a relative URI, It will access files relative to the current XAML page. In your case, while using this in BlankPage1, it will try to access Assets/fonts/NotoSansCJKtc-Thin.otf file in current folder which is the "UI" folder. As there is no such file in "UI" folder, the FontFamily property will use its default value.

To access files relative to the root of the package, from a XAML page, you can use an absolute path URIs (those that begin with a "/") like following:

<TextBlock Margin="0,80,0,0"
               HorizontalAlignment="Center"
               FontFamily="/Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"
               FontSize="80"
               Foreground="#878787">
    微abc012
</TextBlock>

Or using ms-appx: scheme like following:

<TextBlock Margin="0,80,0,0"
           HorizontalAlignment="Center"
           FontFamily="ms-appx:///Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC"
           FontSize="80"
           Foreground="#878787">
    微abc012
</TextBlock>

And FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC" can work, but FontFamily="Assets/fonts/NotoSansCJKtc-Thin.otf#Noto Sans CJK TC Thin" won't.

I have the same issue in my side. Form the otf file, its font name should be "Noto Sans CJK TC Thin".
enter image description here However using this font name won't work both in XAML Designer and run-time. I think this issue may related to the otf file as I tested with some other fonts, they all worked as expected.

I also try to reference other project font resource in same solution.

To reference other project font resource in same solution, you can refer to my previous answer in UWP - Font only applied in Designer.

Community
  • 1
  • 1
Jay Zuo
  • 15,653
  • 2
  • 25
  • 49