2

I have a class that inherits the InkCanvas class. I overridden the VisualChildrenCount property and the GetVisualChild method:

Visual GetVisualChild(int index)
{
    if (index == 0)
    {
        return InkCanvas.GetVisualChild(index);
    }

    return visuals[index - 1].Visual;
}


int VisualChildrenCount
{
    get { return visuals.Count + InkCanvas.VisualChildrenCount; }
}

Where visuals is my collection visual objects, and the Visual property returns a DrawingVisual object. I use this class to add and display DrawingVisual objects (performance reasons):

void AddVisual(MyVisual visual)
{
    if (visual == null)
        throw new ArgumentNullException("visual");

    visuals.Add(visual);
    AddVisualChild(visual->Visual);
    AddLogicalChild(visual->Visual);
}

The problem is the following: when I draw a new Stroke (in a free drawing with the mouse) this stroke is added to the InkCancas but under the previous DrawingVisual (Z-order), therefore if for example I draw the stroke under a big rectangle I can not see anything because the stroke is hidden.

How can I fix this sneaky problem?

Charles
  • 50,943
  • 13
  • 104
  • 142
gliderkite
  • 8,828
  • 6
  • 44
  • 80

1 Answers1

1

Set the InkCanvas' Background property to Transparent (or null) and return the visuals in different order from the GetVisualChild override:

protected override Visual GetVisualChild(int index)
{
    if (index < visuals.Count)
    {
        return visuals[index].Visual;
    }

    return base.GetVisualChild(index - visuals.Count);
}
Clemens
  • 123,504
  • 12
  • 155
  • 268