WPF字體或內(nèi)容模糊的解決方法
本文會給大家介紹嘗試過的一些方法,大家可以一起看看。
1、用WPF4.0中的新字體渲染方法,沒有改善
<Setter Property="TextOptions.TextFormattingMode" Value="Display" /> <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" />
2、給控件加上SnapsToDevicePixels屬性,沒有改善
其作用傳說是給整個 UI 上啟用像素對齊呈現(xiàn)。 對于運行在大于 96 dots per inch (dpi) 的設備,像素對齊呈現(xiàn)可以最小化在單一實線附近出現(xiàn)的抗鋸齒視覺瑕疵。
3、使用Times New Roman字體或微軟雅黑字體,好一點,但是字體比較丑,也不能完全避免虛糊,另外解決不了動畫后,文字繼續(xù)虛邊現(xiàn)象。
4、最終解決
其實是自己的編寫的Border設置了DropShadowEffect(陰影效果)引起的。
因為DropShadowEffect使得元素/子元素先渲染為位圖,從而導致的位圖柵格對齊導致的模糊。
解決方法有幾個:
- 是使用
UseLayoutRounding,它使得控件布局的時候對齊柵格(見效果2)。 - 是讓Text元素不作為
DropShadowEffect的子元素,讓ShadowEffect不會影響Button(見效果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>
總結
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
相關文章
英雄聯(lián)盟輔助lol掛機不被踢的方法(lol掛機腳本)
lol掛機不會被踢,調用API設置鼠標位置并模擬鼠標右鍵讓人物走動2013-12-12
C# readnodefile()不能讀取帶有文件名為漢字的osg文件解決方法
這篇文章主要介紹了C# readnodefile()不能讀取帶有文件名為漢字的osg文件解決方法,需要的朋友可以參考下2015-09-09
c# 從內(nèi)存中釋放Selenium chromedriver.exe
這篇文章主要介紹了c# 從內(nèi)存中釋放Selenium chromedriver.exe的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01
C#利用反射來判斷對象是否包含某個屬性的實現(xiàn)方法
這篇文章主要介紹了C#利用反射來判斷對象是否包含某個屬性的實現(xiàn)方法,很有借鑒價值的一個技巧,需要的朋友可以參考下2014-08-08

