6

Are horizontal or vertical WPF Lines limited to 125,000 pixels? Looking at the following code the Green line displays correctly but the Red one does not display at all despite being just 0.01 longer. Any idea why?

<Window x:Class="DCView.Window11"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window11" Height="300" Width="300">
    <ScrollViewer>
        <Grid Width="150000">
            <Line X1="0" X2="125000.00" Y1="10" Y2="10" StrokeThickness="1" Stroke="Green"></Line>
            <Line X1="0" X2="125000.01" Y1="20" Y2="20" StrokeThickness="1" Stroke="Red"></Line>
        </Grid>     
    </ScrollViewer>
</Window>

Andrew

Andrew Jones
  • 285
  • 3
  • 11

2 Answers2

5

This seems to be a limitation in WPF's handling of vector graphics.

To make it more complicated, try changing the StrokeThickness - if you set the StrokeThickness of your red line from 1 to 2, it displays again... until you increase the length above 250000.. Then it vanishes again.

<Grid>
    <Line X1="0" X2="125000.00" Y1="10" Y2="10" StrokeThickness="1" Stroke="Green"></Line>
    <Line X1="0" X2="250000.00" Y1="20" Y2="20" StrokeThickness="2" Stroke="Red"></Line>
    <Line X1="0" X2="250000.01" Y1="30" Y2="30" StrokeThickness="2" Stroke="Blue"></Line>
</Grid>  

The max length goes up as you increase your stroke thickness.

Also Note that if the line wasn't perfectly horizontal or vertical, the length limit seems to vanish:

<Grid>
    <Line X1="0" X2="125000.00" Y1="10" Y2="10" StrokeThickness="1" Stroke="Green" />
    <Line X1="0" X2="125000.01" Y1="20" Y2="20.0001" StrokeThickness="1" Stroke="Red" />
</Grid>

You can find the bug written up on connect: Disappearing Path (WPF)

Philip Rieck
  • 32,368
  • 11
  • 87
  • 99
  • Philip, I made the line very slightly off horizontal to work around this WPF bug. The strange thing is it does not seem to be documented anywhere (apart from the bug on connect). – Andrew Jones Dec 05 '12 at 21:36
0

It definitely draws past 150,000 pixels, It is a bit strange that the line is not seen in this case, because for example if you do this

<Line X1="0" X2="125000.01" Y1="20" Y2="20" StrokeThickness="2" Stroke="Red"></Line>

or this

<Line X1="0" X2="125000.01" Y1="21" Y2="20" StrokeThickness="1" Stroke="Red"></Line>

all works fine, There is probably a answer somewhere as to why, but good find as this would cause significant flicker if you were animating the value of X2.

sa_ddam213
  • 42,848
  • 7
  • 101
  • 110
  • It would appear that absolutely horizontal or vertical lines with a thickness of 1 are limited to 125000 pixels. A line twice as thick can be twice as long. You can work around the problem by ensuring the line is not exactly horizontal or vertical. It must be a bug or an undocumented limit in WPF. – Andrew Jones Dec 06 '12 at 00:36