3

I am currently designing a layout app in Silverlight and have a Canvas inside of a Viewbox. I add shapes to the canvas and they display properly, when I resize the viewbox to zoom in at 2x the height and width, everything still draws properly.

The problem comes when I try to zoom at a factor of 4 or greater or at 0.5 (zoomed out).

Update: The horizontal lines are still there, they are just not drawing. Interaction between the the other shapes and the disappearing ones is still present

When I do this, any horizontal lines do not redraw, but any other shapes, vertical lines of other, still redraw fine. The objects are still children of the canvas and their visibilities are all set to visible.

What is happening?

Update
Very Simple XAML:

<ScrollViewer x:Name="scrollViewer" 
              Padding="0"
              ScrollViewer.VerticalScrollBarVisibility="Auto"
              ScrollViewer.HorizontalScrollBarVisibility="Auto"
              IsTabStop="False"
              Background="Beige">
    <Viewbox x:Name="viewBox" Stretch="UniformToFill">
        <Canvas x:Name="designCanvas"  
                Background="{Binding ElementName=mainControl, Path=Background, Mode=TwoWay}">
        </Canvas>
    </Viewbox>
</ScrollViewer>

Here is how I add the shapes:

Rectangle horGuide = new Rectangle()
            {
                Tag = "horGuide",
                Fill = new SolidColorBrush(Colors.Cyan),
                Height = 0.5,
                Width = designCanvas.canvActualWidth*16,
            };

            int h = designCanvas.horOffset; 
            int v = designCanvas.vertOffset;
            double d = e.GetPosition(sideRule).Y;

            designCanvas.Children.Add(horGuide);
            Canvas.SetTop(horGuide, ((d+v )/ designCanvas.zoomFactor));
            Canvas.SetLeft(horGuide, 0 - h);

To Zoom in:

       viewBox.Width *= 2;
       viewBox.Height *= 2;
Ty Rozak
  • 471
  • 6
  • 19
  • Great, but that code is not working Canvas.horOffset, Canvas.vertOffset and Canvas.zoomFactor does not exists as a canvas property – danbord Jan 28 '11 at 15:56
  • Those are properties I have to handle other things in my program, they can be replaced with the Horizontal and Vertical Scroll Offset of the scrollviewer. Zoomfactor is multiplicative depending on the amount of zoom. It is just to set the position to where I want it, I believe it is irrelevant to this problem as the position seemed irrelevant to which items were not redrawn. – Ty Rozak Jan 28 '11 at 15:59
  • Have you considered a scale-transform on the canvas instead of a viewbox? – svrist Feb 03 '11 at 19:59
  • I have not, what would be the advantage of this compared to a viewbox, it seems like more calculations would have to be done than just using a simple viewbox? – Ty Rozak Feb 04 '11 at 14:15

1 Answers1

0

Why not use the ScaleTransform class to zoom in and out.