Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Good answers by Spencer and Martin as to the <strong>when</strong> to align your pixels.</p> <p>As to the <strong>how</strong>: I would also point out that one should <em>in WPF 4.0</em> try using the property <strong><code>UseLayoutRounding</code></strong> instead of <code>SnapsToDevicePixels</code>.</p> <p><code>UseLayoutRounding</code> makes what you are doing compatible with Silverlight (<code>SnapsToDevicePixels</code> is not available in Silverlight) ... and Microsoft is also encouraging the use of <code>UseLayoutRounding</code> over <code>SnapsToDevicePixels</code> in its <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.uselayoutrounding(v=VS.100).aspx" rel="noreferrer">documentation</a>.</p> <p>What is the difference between the two? Well, one big difference is that <code>UseLayoutRounding</code> occurs during the layout phase while <code>SnapsToDevicePixels</code> occurs during the render phase. This makes me speculate that <code>UseLayoutRounding</code> is probably a more performant way to go (I haven't confirmed this, though).</p> <p>All that being said, there will still be reasons to use <code>SnapsToDevicePixels</code>. In fact, the MSDN documentation points to one. I will add another: it is only with <code>SnapsToDevicePixels</code> that you can use guidelines for precise control.</p> <p>Here are some resources on this matter (i.e. pixel snapping and clarity with images, text, and visuals):</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels(v=VS.100).aspx" rel="noreferrer">The MSDN Documentation for the UIElement.SnapsToDevicePixels Property.</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.uselayoutrounding(v=VS.100).aspx" rel="noreferrer">The MSDN Documentation for the FrameworkElement.UseLayoutRounding Property.</a></li> <li><a href="http://blogs.msdn.com/dwayneneed/archive/2007/10/05/blurry-bitmaps.aspx" rel="noreferrer">Here is the old, classic post by Dwayne Need on blurry images.</a></li> <li><a href="https://stackoverflow.com/questions/592017/my-images-are-blurry-why-isnt-wpfs-snapstodevicepixels-working">Sometimes BitmapScalingMode helps with image clarity.</a></li> <li><a href="http://www.wpftutorial.net/DrawOnPhysicalDevicePixels.html" rel="noreferrer">A great blog post that shows you how to actually use SnapsToDevicePixels. It can be tricky.</a></li> <li><a href="http://blogs.msdn.com/text/archive/2010/03/05/additional-wpf-text-clarity-improvements.aspx" rel="noreferrer">A blog post by the WPF Text team about all the different improvements they added to WPF 4.0 in order to help text clarity.</a></li> <li><a href="http://blogs.msdn.com/text/archive/2009/08/27/layout-rounding.aspx" rel="noreferrer">Another blog post by the WPF Text team on layout rounding.</a></li> </ul> <p><em>Heh. I know my answer was a little more than what you were asking for ... but this concept (i.e. resolution independence and the resulting problems it brings and how to get over them) can often be a point of <a href="https://stackoverflow.com/questions/1445114/what-did-you-find-hardest-to-understand-when-learning-wpf/1446230#1446230">frustration</a> when working with WPF. At the very least, I wanted to point you to the new WPF 4.0 property, <code>UseLayoutRounding</code>.</em></p> <p><strong>UPDATE</strong></p> <p>I just have to add since I've seen this over and over ... sometimes <code>SnapsToDevicePixels</code> works when <code>UseLayoutRounding</code> doesn't. I wish I could put a finger on why this is the case, but definitely try UseLayoutRounding first and if that doesn't work, don't hesitate to try <code>SnapsToDevicePixels</code>.</p> <p><em>That line is so sharp it can cut you!</em></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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