问题描述
我在使用 WPF 时遇到了一个相当奇怪的问题.当我在表单上放置按钮时,它们在设计时看起来不错,它们在 Windows XP 上看起来不错,但是当应用程序在 Windows 7 上运行时,边缘会损坏.
I’m experiencing a rather strange problem with WPF. When I place buttons on a form they look fine in design time, they look fine on windows XP but when the application is run on windows 7 the edges become broken.
这是正常图标的屏幕截图(XP 和设计时间)
Here is a screen shot of the normal icons (XP and design time)
这是一个边缘破损的地方(Windows 7)
And here is one with the broken edges (windows 7)
有什么想法吗?
这里要求的是我用于按钮的代码
As requested here is the code I use for the button
<Button Height="38" HorizontalAlignment="Center" Name="cmdChange_dataset" VerticalAlignment="Center" Width="130" Grid.Column="0" >
<Grid Width="120">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="/Sales_express_lite_WPF;component/Images/note_to_self_32.png" Stretch="None" Grid.Column="0" HorizontalAlignment="Left"/>
<Label Content="Change DataSet" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Button.Effect>
<DropShadowEffect BlurRadius="5" Color="Gray" />
</Button.Effect>
</Button>
推荐答案
可能与此有关?WPF 文本博客上的布局舍入
博文摘要:
WPF 的布局引擎经常为元素提供子像素位置.抗锯齿算法使这些子像素定位元素在过滤后呈现在多个物理像素上.这可能会导致线条模糊和其他不理想的渲染伪像.WPF 4.0 中引入了布局舍入,允许开发人员强制 WPF 布局系统将元素定位在像素边界上,从而消除子像素定位的许多负面影响.
附加属性 UseLayoutRounding
已被引入以允许打开或关闭布局舍入功能.此属性可以是 True 或 False.此属性的值由元素的子元素继承.
<Grid UseLayoutRounding="True" Height="100" Width="200">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Fill="DarkBlue"/>
<Rectangle Grid.Row="1" Fill="DarkBlue"/>
<Rectangle Grid.Row="2" Fill="DarkBlue"/>
</Grid>
这篇关于WPF 断边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!