具有两个边界的WPF DPI渲染问题 [英] WPF DPI rendering issues with two borders

查看:114
本文介绍了具有两个边界的WPF DPI渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境

Win 8,VS 2012,.NET 4,WPF,屏幕原始分辨率1920x1080 @ 96DPI

Win 8, VS 2012, .NET 4, WPF, screen native resolution 1920x1080@96DPI

XAML

<Border BorderThickness="1" BorderBrush="Red" Width="20" Height="20">
    <Border BorderThickness="1" BorderBrush="Blue" />
</Border>

问题

当DPI为96时,边框看起来很好,但是如果我将DPI更改为120,则边框不再是完全像素对齐的。

The borders look fine when DPI is 96, but if I change the DPI to 120, the borders are no longer perfectly pixel aligned.

我要做什么尝试过

1)设置以下属性- RenderOptions.EdgeMode = Aliased SnapsToDevicePixels = True UseLayoutRounding = True -在两个边界上,都减轻了较高DPI引起的抗锯齿和渗色问题,但内部边界通常在右侧和底部都有1px的边距。

1) Setting the following properties - RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True" - on both borders, mitigates the anti-aliasing and bleeding issues from the higher DPI, but the inner border seems to have a 1px margin usually on the right and bottom sides.

2)以下代码无助于解决此问题:

2) The following code does not help to work around the problem:

<Grid Width="20" Height="20">
    <Border BorderThickness="1" BorderBrush="Red" />
    <Border BorderThickness="1" BorderBrush="Blue" Margin="1" />
</Grid>

3)使用矩形代替边框也有同样的问题。

3) Using Rectangles instead of Borders has the same problem.

4)在VirtualBox中运行的来宾Win 7下,该问题仍然存在。

4) The problem also persists under a guest Win 7 running in VirtualBox.

5)编辑-这看起来像更好一点,因为没有内部边距,但是外部边界为2px厚:

5) Edit - This looks a bit better, in that there is no inner margin, but the outer "border" is 2px thick:

<Canvas Width="20" Height="20">
    <Polygon Points="0,0 20,0, 20,20, 0,20" StrokeThickness="1" Stroke="Red" RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True" />
    <Polygon Points="1,1 19,1, 19,19, 1,19" StrokeThickness="1" Stroke="Blue" RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True" />
</Canvas>

问题

如何在没有任何内部边距或抗锯齿/渗色的情况下使边框达到像素完美?

How do I get the borders to be pixel perfect without any inner margins or anti-alising/bleeding?

我不能使用隐藏代码进行返工DPI大于96时,边框大小会限制。我必须仅坚持使用XAML,因为我正试图创建矢量图标(基于XAML)。

I cannot use code-behind to rework the borders sizes when DPI is other than 96. I must stick to XAML only, because I'm trying to create vector icons (based on XAML).

推荐答案

Bravo Microsoft- https://connect.microsoft.com/VisualStudio/feedback/details/798513/wpf-dpi-rendering-issues-with-two-borders

Bravo Microsoft - https://connect.microsoft.com/VisualStudio/feedback/details/798513/wpf-dpi-rendering-issues-with-two-borders

再次,此问题将不会得到解决或解决。

Yet again, this issue will not be addressed nor fixed.

这篇关于具有两个边界的WPF DPI渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆