简体   繁体   中英

C# winrt/metro app, WebView custom font

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM