Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DPI rendering issues with two borders
    primarykey
    data
    text
    <p><strong>Enviroment</strong></p> <p>Win 8, VS 2012, .NET 4, WPF, screen native resolution 1920x1080@96DPI</p> <p><strong>XAML</strong></p> <pre><code>&lt;Border BorderThickness="1" BorderBrush="Red" Width="20" Height="20"&gt; &lt;Border BorderThickness="1" BorderBrush="Blue" /&gt; &lt;/Border&gt; </code></pre> <p><strong>The problem</strong></p> <p>The borders look fine when DPI is 96, but if I change the DPI to 120, the borders are no longer perfectly pixel aligned.</p> <p><strong>What I have tried</strong></p> <p>1) Setting the following properties - <code>RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True"</code> - 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.</p> <p>2) The following code does not help to work around the problem:</p> <pre><code>&lt;Grid Width="20" Height="20"&gt; &lt;Border BorderThickness="1" BorderBrush="Red" /&gt; &lt;Border BorderThickness="1" BorderBrush="Blue" Margin="1" /&gt; &lt;/Grid&gt; </code></pre> <p>3) Using Rectangles instead of Borders has the same problem.</p> <p>4) The problem also persists under a guest Win 7 running in VirtualBox.</p> <p>5) <strong>Edit</strong> - This looks a bit better, in that there is no inner margin, but the outer "border" is 2px thick:</p> <pre><code>&lt;Canvas Width="20" Height="20"&gt; &lt;Polygon Points="0,0 20,0, 20,20, 0,20" StrokeThickness="1" Stroke="Red" RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True" /&gt; &lt;Polygon Points="1,1 19,1, 19,19, 1,19" StrokeThickness="1" Stroke="Blue" RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True" UseLayoutRounding="True" /&gt; &lt;/Canvas&gt; </code></pre> <p><strong>Question(s)</strong></p> <p>How do I get the borders to be pixel perfect without any inner margins or anti-alising/bleeding?</p> <p>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).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload