Why does UseLayoutRounding not work with Viewbox?

I'm trying to write a tile-based game in WPF 4. I want the game bar to scale to fit the window, so I use Viewbox; but I want every tile to be on a nice, clear pixel border. Maybe I'm wrong, but I understand that this should be a new UseLayoutRounding property, but it does not work as I expect.

A window is displayed here that demonstrates the problem:

<Window x:Class="Tyler.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="600" Height="400" Background="Black"> <Viewbox> <Canvas Width="1000" Height="1000"> <Rectangle Canvas.Left="100" Canvas.Top="100" Width="100" Height="100" Fill="Gray"/> <Rectangle Canvas.Left="200" Canvas.Top="100" Width="100" Height="100" Fill="Gray"/> </Canvas> </Viewbox> </Window> 

The two rectangles are adjacent, but due to the sub-pixel coordinates (as a result of the Viewbox scaling), I finish the dark gray seam between them. This is what I'm trying to get rid of - I want them to merge seamlessly.

But UseLayoutRounding does not seem to have such an effect. I tried to set UseLayoutRounding="True" in the window, in the View, Canvas, Rectangles window - I even tried to put it on everyone at once. It does not affect the seam.

What am I missing (or misunderstanding)? How can I get a rounding layout for working with Viewbox?

0
source share
1 answer

SnapsToDevicePixels=True is what you want

 <Viewbox SnapsToDevicePixels="True" > <Canvas Width="1000" Height="1000"> <Rectangle Canvas.Left="100" Canvas.Top="100" Width="100" Height="100" Fill="Gray"/> <Rectangle Canvas.Left="200" Canvas.Top="100" Width="100" Height="100" Fill="Gray"/> </Canvas> </Viewbox> 
+3
source

All Articles