Why the Path and Polyline have different renderings in WPF?
c#, path, polyline, wpf, xaml
Solution
It has to do with drawing modes of non-text objects. I tried setting the polyline object like the article linked below says and it does make it look just like the path.
So, short answer is it has to do with anti-aliasing. Here is the article: Single Pixel Lines
If you want the command here it is, give your polyline a Name and then add the following to the code behind.
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
// THIS IS THE LINE THATS IMPORTANT
pLine.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
}
}
Your xaml change here:
<Polyline x:Name="pLine" Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100">
<Polyline.Points>
<Point>10,0</Point>
<Point>10,100</Point>
</Polyline.Points>
</Polyline>
This will make your polyline object look just like your Path object. However changing the Path to use unspecified does not do anything so you can make your other objects look similar to the path but not vice versa.
Problem
Why the Path and Polyline have different renderings in WPF? This is happening both in code and blend, maybe a I missing something or this is just a anti aliasing effect. ``` <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="GeometryMonky.Window1" x:Name="Window" Title="Window1" Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid x:Name="LayoutRoot"> <Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF0000FF" Margin="100,10,0,0" Data="M289,39 L333,173" Width="1" HorizontalAlignment="Left" Height="100" StrokeThickness="1"/> <Polyline Stroke="#FF0000FF" Margin="115,178,417,168" StrokeThickness="1" Width="100" Height="100"> <Polyline.Points> <Point>10,0</Point> <Point>10,100</Point> </Polyline.Points> </Polyline> </Grid> </Window> ``` Image sample from Blend: http://img190.imageshack.us/img190/2965/wpfsmaple.png Development system: WinXP SP2, VS 2008 + SP1