WPF 断边
我在使用 WPF 时遇到了一个相当奇怪的问题。当我将按钮放置在窗体上时,它们在设计时看起来很好,在 Windows XP 上看起来也很好,但当应用程序在 Windows 7 上运行时,边缘会损坏。
这是正常图标的屏幕截图(XP 和设计时)
这是一个边缘破损的 (windows 7)
有什么想法吗?
编辑:
按照此处的要求是我用于按钮的代码
<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>
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.
Here is a screen shot of the normal icons (XP and design time)
And here is one with the broken edges (windows 7)
Any ideas?
EDIT:
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许与此有关?
WPF 文本博客上的布局舍入
博客文章摘要:
WPF 的布局引擎经常给出元素的子像素位置。抗锯齿算法使这些子像素定位的元素在过滤后在多个物理像素上渲染。这可能会导致线条模糊和其他不理想的渲染伪像。 WPF 4.0 中引入了布局舍入,允许开发人员强制 WPF 布局系统将元素定位在像素边界上,从而消除了子像素定位的许多负面影响。
附加属性
UseLayoutRounding
已被引入以允许打开或关闭布局舍入功能。该属性可以是 True 或 False。该属性的值由元素的子元素继承。
Maybe is related to this?
Layout Rounding on the WPF Text Blog
Summary from the blog post:
WPF’s layout engine frequently gives elements sub-pixel positions. Antialiasing algorithms cause these sub-pixel positioned elements to be rendered over multiple physical pixels after filtering. This can result in blurry lines and other non desirable rendering artifacts. Layout rounding has been introduced in WPF 4.0 to allow developers to force the WPF layout system to position elements on pixel boundaries, eliminating many of the negative side effects of sub-pixel positioning.
The attached property
UseLayoutRounding
has been introduced to allow layout rounding functionality to be toggled on or off.This property can either be True or False. The value of this property is inherited by an element’s children.