0
votes

Does anyone know how to load custom fonts in a WebView?
What I have tried:

@font-face {
     font-family: 'Gloria Hallelujah';
     font-style: normal;
     font-weight: 400;
     src: url(Gloria.woff);
 }

According this.

But the thing is, that this works ONLY when we call WebView.Navigate(urlToHtmlDocWithCustomFonts);
But in my case I'm calling WebView.NavigateToString(htmlStringWithCustomFonts); and in this case custom fonts don't works!

Here is the project with sources from that tuto in case if you want to reproduce: link.

So my question is, is it possible to load a html string into a webview with custom fonts?

1

1 Answers

0
votes

Use WebView.NavigateToLocalStreamUri instead of NavigateToString. This will let you provide an IUriToStreamResolver to stream referenced files such as images and your font files into your page. With NavigateToString you'd need to encode them within the stream as NavigateToString doesn't have context to look up and find referenced files such as Gloria.woff.

MSDN's XAML WebView control sample demonstrates writing and using a resolver to stream in the referenced file.