Visual.IsPixelSnappingEnabled Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that indicates whether the composition engine aligns the rendered visual with a pixel boundary.
public:
property bool IsPixelSnappingEnabled { bool get(); void set(bool value); };
bool IsPixelSnappingEnabled();
void IsPixelSnappingEnabled(bool value);
public bool IsPixelSnappingEnabled { get; set; }
var boolean = visual.isPixelSnappingEnabled;
visual.isPixelSnappingEnabled = boolean;
Public Property IsPixelSnappingEnabled As Boolean
Property Value
bool
true
if the composition engine aligns the rendered visual with a pixel boundary; otherwise, false
. The default is false
.
Examples
public Visual CreateVisualTree(Compositor compositor)
{
// Say we have two visuals, one containing an image and one containing text.
// The image can be resampled and still look fine, but the text looks bad if
// it doesn't land perfectly on pixel boundaries.
var root = compositor.CreateContainerVisual();
var imageVisual = compositor.CreateSpriteVisual();
ImageLoadingHelper(imageVisual);
var textVisual = compositor.CreateSpriteVisual();
TextLoadingHelper(textVisual);
textVisual.Offset = new Vector3(50, 0, 0);
textVisual.IsPixelSnappingEnabled = true;
root.Children.Add(imageVisual);
root.Children.Add(textVisual);
return root;
}
Remarks
Pixel snapping lets you request that the composition engine adjust the position of a visual tree slightly at render time so that its origin aligns perfectly with a pixel boundary. This sacrifices positional accuracy in exchange for reduced sampling artifacts for textures.