本文會給大家介紹嘗試過的一些方法,大家可以一起看看。
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
使得元素/子元素先渲染為位圖,從而導致的位圖柵格對齊導致的模糊。
解決方法有幾個:
UseLayoutRounding
,它使得控件布局的時候對齊柵格(見效果2)。DropShadowEffect
的子元素,讓ShadowEffect
不會影響Button
(見效果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" <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>
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點
疑難解答