Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.0 C# WPF
Hi all,
 
I have a large Canvas which can be scrolled horizontally. My Canvas contains little lines (StrokeThickness = 1) positioned uniformly. When I scroll to right the lines start to disappear and appear when reaching an horizontal offset of 8.000.000 (more or less). How can I fix it?
 
Here an example. 10 lines to left, 10 lines to right. The first lines are visible while the last ones are partially visible (5 visible, 5 not).
<Window x:Class="WpfApplication.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Visible">
            <Canvas Width="15000000">
                <Line Canvas.Left="0" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="5" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="10" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="15" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="20" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="25" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="30" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="35" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="40" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="45" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999950" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999955" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999960" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999965" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999970" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999975" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999980" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999985" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999990" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
                <Line Canvas.Left="14999995" X1="0" X2="0" Y1="0" Y2="100" Stroke="Black" StrokeThickness="1" />
            </Canvas>
        </ScrollViewer>
    </Grid>
</Window>
 
Thanks,
 
Raúl
Posted 6-May-11 1:26am
Edited 6-May-11 5:22am
v3
Comments
SAKryukov at 6-May-11 8:48am
   
How can the lines disappear when they are "far away from left"? They should not appear in first place... Are you sure it's a problem? Explain more clearly, make a code sample. (Not post all your code, create a special simplest sample to show the problem!)
--SA
Raúl Nuño at 6-May-11 10:20am
   
Ok, I've edited the question and I've added a code sample.
TheyCallMeMrJames at 6-May-11 10:30am
   
Set your stroke thickness to 2 and try again. I think you're running into an anti-aliasing thing here.
Raúl Nuño at 6-May-11 10:44am
   
Yes, I know that making the stroke thickness bigger the lines don't disappear but I don't want to change it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Instead of using a canvas that's THAT frickin' wide, I'd be owner drawing only what's visible. You're just asking for trouble trying to do it this way. Since a monitor normally isn't any wider than about 2000 pixels, there's no point in making an image that's 15,000,000 pixels wide.
  Permalink  
Comments
SAKryukov at 6-May-11 11:32am
   
Good idea, my 5. (Original idea is just bad.) Zooming can be helpful, zoom to selection and other civilized stuff.
--SA
Raúl Nuño at 9-May-11 4:23am
   
I'm drawing only what's visible (elements in the visible part) and I need this big width in order to modify it (zoom in/out) and scroll the content (furthermore, I need to synchronize another panel scroll). What's the problem on having a wide canvas?
Dave Kreskowiak at 9-May-11 10:49am
   
The first is a bitmap, at 15,000,000 and ONE PIXEL HIGH, uses 45 MB of memory (32 bits per pixel). Does that sound like a good idea?
 
Your code is saying that your NOT drawing just what's visible. You're drawing the entire grid all at once. Your drawing surface should only be the size of the visible viewport.
Raúl Nuño at 3-Jun-11 18:25pm
   
Sorry for the delay, I have been a little busy...
 
Are you sure WPF canvas maintains the state of each pixel in memory? I can make an Int32.MaxValue x Int32.MaxValue canvas without getting System.OutOfMemoryException. I'm curious on that.
 
And YES, I'm drawing just what's visible. The code above is a simple example to show my problem.
 
In summary, I can't have a wide canvas?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In this page http://connect.microsoft.com/VisualStudio/feedback/details/731467/disappearing-path-wp[^] you can find the reason of why the lines disappear.
I had the same problem, then i split the lines in function of its length
  Permalink  
Comments
Raúl Nuño at 28-Oct-12 10:37am
   
Wow... long time since I posted the question. I can't remember how I solved this.
 
So this is a WPF limitation. Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 25 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100