当前位置: 移动技术网 > IT编程>开发语言>c# > WPF字体或内容模糊的解决方法

WPF字体或内容模糊的解决方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文会给大家介绍尝试过的一些方法,大家可以一起看看。

1、用wpf4.0中的新字体渲染方法,没有改善

<setter property="textoptions.textformattingmode" value="display" />
<setter property="textoptions.textrenderingmode" value="cleartype" />

2、给控件加上snapstodevicepixels属性,没有改善

其作用传说是给整个 ui 上启用像素对齐呈现。 对于运行在大于 96 dots per inch (dpi) 的设备,像素对齐呈现可以最小化在单一实线附近出现的抗锯齿视觉瑕疵。

3、使用times new roman字体或微软雅黑字体,好一点,但是字体比较丑,也不能完全避免虚糊,另外解决不了动画后,文字继续虚边现象。

4、最终解决

其实是自己的编写的border设置了dropshadoweffect(阴影效果)引起的。

因为dropshadoweffect使得元素/子元素先渲染为位图,从而导致的位图栅格对齐导致的模糊。

解决方法有几个:

  1. 是使用uselayoutrounding,它使得控件布局的时候对齐栅格(见效果2)。
  2. 是让text元素不作为dropshadoweffect的子元素,让shadoweffect不会影响button(见效果3)。
  3. 效果如下(0:基准      1:虚糊        2:uselayoutrounding      3:平行元素)

效果4是试验systemdropshadowchrome,可以注释掉。

<window x:class="wpfapplication1.mainwindow"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:luna="clr-namespace:microsoft.windows.themes;assembly=presentationframework.luna"
 title="mainwindow" height="350" width="525" snapstodevicepixels="true">
 <window.resources>
  <style targettype="button">
   <setter property="width" value="80" />
   <setter property="height" value="40" />
   <setter property="margin" value="0,5,0,5" />
  </style>
 </window.resources>
 <stackpanel>
  <button content="基本设置 0" />
  <button content="基本设置 1" >
   <button.effect><dropshadoweffect/></button.effect>
  </button>
  <button content="基本设置 2" uselayoutrounding="true">
   <button.effect>
    <dropshadoweffect/>
   </button.effect>
  </button>
  <grid width="80" height="40" margin="0,5,0,5">
   <border background="black" margin="1,0,0,0" cornerradius="2">
    <border.effect><dropshadoweffect /></border.effect>
   </border>
   <button content="基本设置 3" margin="0"/>
  </grid>
  <luna:systemdropshadowchrome width="80" height="40" margin="0,5,0,0">
   <button content="基本设置 4" margin="0" />
  </luna:systemdropshadowchrome>
 </stackpanel>
</window>

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网