Items not drawing on Resize of Viewbox, Silverlight

931 views Asked by At

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;
1

There are 1 answers

0
AudioBubble On BEST ANSWER

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