Hello.
I wrote an application with next descendant of Canvas
I use this control to add two complex DrawVisual objects via DrawingContext in the runtime (DrawLine, DrawEllipse, DrawGeometry are used). So, count of visuals in the DrawingCanvas is 6. This control works properly and displays all visual as I need.
I found that GetVisualChild() method called very often, it is called even I just move mouse cursor above DrawingCanvas, and there are no useful actions. When DrawVisual became very big (50-70 graphic primitives), application take more and more processor resources while mouse cursor moving.
Anybody may explain this?
I wrote an application with next descendant of Canvas
public class DrawingCanvas: Canvas
{
List<Visual> _visuals = new List<Visual>();
protected override int VisualChildrenCount
{
get
{
return base.VisualChildrenCount + _visuals.Count;
}
}
protected override Visual GetVisualChild(int index)
{
if (index < base.VisualChildrenCount)
return base.GetVisualChild(index);
else
return _visuals[index - base.VisualChildrenCount];
}
internal void AddVisual(Visual visual)
{
_visuals.Add(visual);
base.AddVisualChild(visual);
base.AddLogicalChild(visual);
}
internal void AddVisual(Visual visual, bool addLogicalChild)
{
_visuals.Add(visual);
base.AddVisualChild(visual);
}
internal void RemoveVisual(Visual visual)
{
_visuals.Remove(visual);
base.RemoveVisualChild(visual);
base.RemoveLogicalChild(visual);
}
internal void ClearVisuals()
{
foreach (Visual visual in _visuals)
{
base.RemoveVisualChild(visual);
base.RemoveLogicalChild(visual);
}
_visuals.Clear();
}
internal DrawingVisual GetVisual(Point point)
{
HitTestResult htr = VisualTreeHelper.HitTest(this, point);
return htr.VisualHit as DrawingVisual;
}
}
<ctrl:DrawingCanvas x:Name="drawArea"><!-- 4 children objects --> <Image.../><Path.../><Line.../><Line.../></ctrl:DrawingCanvas>
I use this control to add two complex DrawVisual objects via DrawingContext in the runtime (DrawLine, DrawEllipse, DrawGeometry are used). So, count of visuals in the DrawingCanvas is 6. This control works properly and displays all visual as I need.
I found that GetVisualChild() method called very often, it is called even I just move mouse cursor above DrawingCanvas, and there are no useful actions. When DrawVisual became very big (50-70 graphic primitives), application take more and more processor resources while mouse cursor moving.
Anybody may explain this?