企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
 wpf中经常遇到各种和文字渲染有关的问题, 现在列举下现象和解决方案。 **(1)** 现象: 文字大小不一,不在同一水平线, 不同字渲染成同一个字, 或者字体发虚 ![](https://box.kancloud.cn/2016-02-02_56b0015b5b710.jpg) 原因:微软雅黑字体对中文字符的渲染支持不好,下面给出系统推荐的语言字体设置表,而且MSFT在内置的位图映射表中对东亚字符进行了优化。 <table align="center" style="border-collapse: collapse; border-spacing: 0px;" border="1" cellspacing="0" cellpadding="0"><tbody><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Language</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Font</p></td></tr><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Traditional Chinese</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">MingLiu</p></td></tr><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Simplified Chinese</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">SimSun</p></td></tr><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Japanese</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">MS Gothic</p></td></tr><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Korean</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Gulium</p></td></tr><tr><td width="175" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Korean</p></td><td width="150" valign="top" style="margin: 0px; padding: 0px; border: currentColor; border-image: none; line-height: 18px; font-family: Verdana, Helvetica, Arial; font-size: 12px; -ms-word-break: break-all;"><p style="margin: 5px auto; padding: 0px; border: currentColor; border-image: none; line-height: 25px;">Batang</p></td></tr></tbody></table> 解决办法: 按照推荐表,中文尽量选择SimSun,效果如下: ![](https://box.kancloud.cn/2016-02-02_56b0015b73af4.jpg) **(2)** 现象:放在ViewBox中时, 发生模糊 ![](https://box.kancloud.cn/2016-02-02_56b0015b841db.jpg) 原因:未知 解决办法:更改TextFormattingMode为Ideal ![](https://box.kancloud.cn/2016-02-02_56b0015b972aa.jpg) **(3)** 现象:TextBlock在Popup中自动换行时, 如果文字中包含‘-’, 即Minus,每行的最后一个字丢失 ![](https://box.kancloud.cn/2016-02-02_56b0015ba54a6.jpg) 原因:未知 解决办法:更改TextFormattingMode为Ideal ![](https://box.kancloud.cn/2016-02-02_56b0015bbae60.jpg) **(4)** 现象:文字发绿,显示多彩不正常 ![](https://box.kancloud.cn/2016-02-02_56b0015bd2015.jpg) 解决办法: 更新显卡驱动,确认系统ClearType是否开启。 参考: [http://blogs.msdn.com/b/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx](http://blogs.msdn.com/b/text/archive/2009/08/24/wpf-4-0-text-stack-improvements.aspx) [https://msdn.microsoft.com/zh-cn/library/system.windows.media.textrenderingmode(v=vs.100).aspx](https://msdn.microsoft.com/zh-cn/library/system.windows.media.textrenderingmode(v=vs.100).aspx) [https://msdn.microsoft.com/zh-cn/library/system.windows.media.textformattingmode(v=vs.100).aspx](https://msdn.microsoft.com/zh-cn/library/system.windows.media.textformattingmode(v=vs.100).aspx) [https://msdn.microsoft.com/zh-cn/library/system.windows.media.texthintingmode(v=vs.100).aspx](https://msdn.microsoft.com/zh-cn/library/system.windows.media.texthintingmode(v=vs.100).aspx) [![](https://box.kancloud.cn/2016-02-02_56b0015bea016.jpg)](#)