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?

4

1 回答 1

1

将 InkCanvas 的Background属性设置为Transparent(或null) 并以与 GetVisualChild 覆盖不同的顺序返回视觉效果:

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

    return base.GetVisualChild(index - visuals.Count);
}
于 2013-10-26T13:36:50.693 回答