Windows phone 8 是否可以使用css在web浏览器控件上的windows phone 8上添加自定义字体

Windows phone 8 是否可以使用css在web浏览器控件上的windows phone 8上添加自定义字体,windows-phone-8,Windows Phone 8,是否可以在windows phone 8 html5应用程序上使用带有css和html的web浏览器控件支持自定义字体。如果可能的话,告诉我怎么做 蒂纳克斯 迪内什看,你已经找到了解决办法。但有人一直在寻找解决方案,我的答案如下: (1) 。使用嵌入式字体创建CSS body, a, p, span, div, textarea { font-family: MyCustomFont; } @font-face { font-family: MyCustomFont;

是否可以在windows phone 8 html5应用程序上使用带有css和html的web浏览器控件支持自定义字体。如果可能的话,告诉我怎么做

蒂纳克斯
迪内什

看,你已经找到了解决办法。但有人一直在寻找解决方案,我的答案如下:

(1) 。使用嵌入式字体创建CSS

body, a, p, span, div, textarea {
        font-family: MyCustomFont;
}

@font-face {
    font-family: MyCustomFont;
    src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAXXXXXXXXXXX......) format('woff');
    font-weight: normal;
    font-style: normal;
} 
(2.)在WebView_NavigationCompleted方法中插入jQuery和CSS

 private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
 {
    // Inject jQuery file which located at local
    StorageFile jquery = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///JavaScripts\\jquery-1.10.2.min.js"));
        string jquery_string = await FileIO.ReadTextAsync(jquery);
        await MyWebView.InvokeScriptAsync("eval", new string[] { jquery_string });


    // Inject custom font embedded CSS 
    StorageFile myfontcss = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///CSS\\mycustomfont.css"));
            string myfontcss_string = await FileIO.ReadTextAsync(myfontcss);

            myfontcss_string = myfontcss_string.Replace("\n", "").Replace("\t", ""); //.Replace("'", "'").Replace("\"", """);
            string cssRef = "$(\"<style id='myfont' type='text/css'>" + myfontcss_string + "</style>\").appendTo('head');";

            await MyWebView.InvokeScriptAsync("eval", new string[] { cssRef });

 }
private async void MyWebView\u导航已完成(WebView发件人、WebViewNavigationCompletedEventArgs args args)
{
//插入位于本地的jQuery文件
StorageFile jquery=等待StorageFile.GetFileFromApplicationUriAsync(新Uri(“ms”)-appx:///JavaScripts\\jquery-1.10.2.min.js);
string jquery\u string=await FileIO.ReadTextAsync(jquery);
等待MyWebView.InvokeScriptAsync(“eval”,新字符串[]{jquery_string});
//注入自定义字体嵌入CSS
StorageFile myfontcss=等待StorageFile.GetFileFromApplicationUrisync(新Uri(“ms”)-appx:///CSS\\mycustomfont.css);
string myfontcss_string=wait FileIO.ReadTextAsync(myfontcss);
myfontcss_string=myfontcss_string.Replace(“\n”和“)。Replace(“\t”和“)/。Replace(“”、“';”)。Replace(“\”、“";”);
字符串cssRef=“$(\”+myfontcss\u字符串+“\”)。附录('head');”;
等待MyWebView.InvokeScriptAsync(“eval”,新字符串[]{cssRef});
}

看,你已经找到了解决方案。但是有人一直在寻找解决方案,下面是我的答案:

(1) .使用嵌入字体创建CSS

body, a, p, span, div, textarea {
        font-family: MyCustomFont;
}

@font-face {
    font-family: MyCustomFont;
    src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAXXXXXXXXXXX......) format('woff');
    font-weight: normal;
    font-style: normal;
} 
(2.)在WebView_NavigationCompleted方法中插入jQuery和CSS

 private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
 {
    // Inject jQuery file which located at local
    StorageFile jquery = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///JavaScripts\\jquery-1.10.2.min.js"));
        string jquery_string = await FileIO.ReadTextAsync(jquery);
        await MyWebView.InvokeScriptAsync("eval", new string[] { jquery_string });


    // Inject custom font embedded CSS 
    StorageFile myfontcss = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///CSS\\mycustomfont.css"));
            string myfontcss_string = await FileIO.ReadTextAsync(myfontcss);

            myfontcss_string = myfontcss_string.Replace("\n", "").Replace("\t", ""); //.Replace("'", "&#39;").Replace("\"", "&#34;");
            string cssRef = "$(\"<style id='myfont' type='text/css'>" + myfontcss_string + "</style>\").appendTo('head');";

            await MyWebView.InvokeScriptAsync("eval", new string[] { cssRef });

 }
private async void MyWebView\u导航已完成(WebView发件人、WebViewNavigationCompletedEventArgs args args)
{
//插入位于本地的jQuery文件
StorageFile jquery=等待StorageFile.GetFileFromApplicationUriAsync(新Uri(“ms”)-appx:///JavaScripts\\jquery-1.10.2.min.js);
string jquery\u string=await FileIO.ReadTextAsync(jquery);
等待MyWebView.InvokeScriptAsync(“eval”,新字符串[]{jquery_string});
//注入自定义字体嵌入CSS
StorageFile myfontcss=等待StorageFile.GetFileFromApplicationUrisync(新Uri(“ms”)-appx:///CSS\\mycustomfont.css);
string myfontcss_string=wait FileIO.ReadTextAsync(myfontcss);
myfontcss_string=myfontcss_string.Replace(“\n”和“)。Replace(“\t”和“)/。Replace(“”、“';”)。Replace(“\”、“";”);
字符串cssRef=“$(\”+myfontcss\u字符串+“\”)。附录('head');”;
等待MyWebView.InvokeScriptAsync(“eval”,新字符串[]{cssRef});
}