WPF 断边

发布于 2024-12-08 08:15:28 字数 1271 浏览 1 评论 0原文

我在使用 WPF 时遇到了一个相当奇怪的问题。当我将按钮放置在窗体上时,它们在设计时看起来很好,在 Windows XP 上看起来也很好,但当应用程序在 Windows 7 上运行时,边缘会损坏。

这是正常图标的屏幕截图(XP 和设计时) Normal Edges

这是一个边缘破损的 (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)
Normal Edges

And here is one with the broken edges (windows 7)
Broken Edges

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2024-12-15 08:15:28

也许与此有关?
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>

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.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文