T-Mac,
T-Mac wrote:
I was also able to reproduce this effect in a test project by drawing two WPF rectangles on a black background. Turn SnapsToDevicePixels to true for one of them, and you can clearly see the difference between them.
An interesting issue. Please let me explain.
I've created a little UserControl to try and illustrate the issue. Here's the code behind:
Code: Select all
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
InitializeCanvas();
InitializeOther();
}
private void InitializeOther()
{
this.SnapsToDevicePixels = true;
}
private void InitializeCanvas()
{
canvas1.Background = new SolidColorBrush(Colors.Black);
Rectangle rect = new Rectangle();
rect.Width = 100;
rect.Height = 100;
rect.SnapsToDevicePixels = false;
rect.Fill = new SolidColorBrush(Colors.Yellow);
rect.Stroke = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(rect, 10);
Canvas.SetTop(rect, 10);
canvas1.Children.Add(rect);
Rectangle rect1 = new Rectangle();
rect1.Width = 100;
rect1.Height = 100;
rect1.SnapsToDevicePixels = true;
rect1.Fill = new SolidColorBrush(Colors.Yellow);
rect1.Stroke = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(rect1, 150);
Canvas.SetTop(rect1, 10);
canvas1.Children.Add(rect1);
}
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), null, new Rect(RenderSize));
drawingContext.DrawRectangle(new SolidColorBrush(Colors.Yellow), new Pen(new SolidColorBrush(Colors.Red), 1), new Rect(10, 150, 100, 100));
}
}
}
And here's the XAML:
Code: Select all
<UserControl x:Class="WpfControlLibrary1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Canvas Margin="0,0,0,150" Name="canvas1" />
</Grid>
</UserControl>
With any luck you should easily be able to drop this code into to a default-created UserControl and then drop the UserControl into a standard WPF Application.
Please understand that TChart does not paint objects by adding Shapes to a canvas, as can be seen in InitializeCanvas(). Rather, it draws directly to the DrawingContext, as in the code in the OnRender() overload.
Having said that, try as I might I cannot see a difference between the top two rectangles, both derived from System.Windows.Shapes.Shape, one with SnapsToDevicePixels set to true and the other set to false. Even commenting out the call to SnapsToDevicePixels in InitializeOther(), which sets the property on the UserControl itself and which should make the difference obvious, doesn't seem to make a visible difference to me.
On the other hand, there is a case that the rectangle drawn directly to the DrawingContext is blurrier than the other two. This rendering does not seem affected at all by SnapsToDevicePixels. Reading the following:
http://msdn.microsoft.com/en-us/library ... S.85).aspx (sorry, this link is not parsed correctly by this version of phpBB)
makes things clearer as to what is going on here. As it says in that article "To set guidelines on Drawing and DrawingContext objects, the GuidelineSet class is used." Well, at the moment we do not use the GuidelineSet class in TChart. We will definitely look into doing so, however, for future releases.