wpf canvas confusion

dpbouchard
dpbouchard used Ask the Experts™
on
<Canvas Margin="2" Name="cvsText" Grid.Column="1" Grid.Row="1" ClipToBounds="True">
   <Canvas Name="cvsChart" ClipToBounds="True"/>
   <Canvas Name="cvsInputs" ClipToBounds="True"/>
</Canvas>

I have the above xaml for a 2d drawing app.  On the cvsText object, I'm drawing the x and y grid lines and all works fine.  On the cvsChart object, I'm drawing the polygon objects of my app.  On the cvsInputs I need to draw the graphic objects that change based upon the user inputs.  What I am trying to do is to use the cvsInputs canvas to draw things that I need to clear every time the user input changes,  However, every time I write on that layer, using the below vb code, nothing happens.  I've tried everything i could think of, changing the zindex of the canvas cvsInputs, the z index of the polygon, all to no avail. Any ideas as to why nothing I draw on the cvsInputs canvas shows up???  When I change only the target canvas to cvsChart, everything shows up just fine so I know the data is being read from the excel sheet just fine.

    Private Sub DrawMacAdamsElipse()

        Dim clsBBLCTR As classBBLCtr
        Dim pl As Polyline
        Dim intRow As Integer
        Dim intLastRow As Integer
        Dim dblX As Double
        Dim dblY As Double

        Canvas.SetZIndex(cvsInputs, 1)
        cvsInputs.Children.Clear()

        If CInt(_ws_ColorCalc.Range(_rngCCTIndex.Address).Value) > 1 Then

            clsBBLCTR = _dictBBLCTR(_clsResults.TargetCCT.ToString)
            If clsBBLCTR IsNot Nothing Then

                'todo: add point code

            End If

            If CInt(_ws_ColorCalc.Range(_rngNumMAEsteps.Address).Value) > 1 Then

                pl = New Polyline
                pl.Stroke = Brushes.Black
                pl.StrokeThickness = 2
                'pl.FillRule = FillRule.EvenOdd

                intRow = 1
                intLastRow = _rngMacAdamsEllipse.Rows.Count

                Do

                    If intRow > intLastRow Then Exit Do

                    dblX = CDbl(GetCellValue(_ws_CIE1976_MAE.Range(_rngMacAdamsEllipse.Address).Cells(intRow, 1)))
                    dblY = CDbl(GetCellValue(_ws_CIE1976_MAE.Range(_rngMacAdamsEllipse.Address).Cells(intRow, 2)))
                    pl.Points.Add(NormalizePoint(New Point(dblX, dblY)))

                    intRow += 1

                Loop

                cvsInputs.Children.Add(pl)

            End If

        End If

    End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hi,

It's because your nested Canvas' have 0 size, give them a width and height and you'll see your drawings;

HTH

Mike
    <Canvas Margin="2" 
            Name="cvsText" 
            ClipToBounds="True" 
            Width="525" 
            Height="350" >
        <Canvas Name="cvsChart" 
                ClipToBounds="True" 
                Width="{Binding ElementName=cvsText, Path=Width}" 
                Height="{Binding ElementName=cvsText, Path=Height}" />
        <Canvas Name="cvsInputs" 
                ClipToBounds="True" 
                Width="{Binding ElementName=cvsText, Path=Width}" 
                Height="{Binding ElementName=cvsText, Path=Height}" />
    </Canvas>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial