public void DrawingGraphics(Geometry positiveGroup, Geometry negativeGroup, bool IsDrawingLine, double CustomDrawLineWidth, DoubleCollection guidlinesX, DoubleCollection guidlinesY) { positiveGroup.Freeze(); negativeGroup.Freeze(); DrawingVisual drawingVisual = new DrawingVisual(); RedBrush.Freeze(); GreenBrush.Freeze(); Pen RedPen = new Pen(RedBrush, CustomDrawLineWidth); Pen GreenPen = new Pen(GreenBrush, CustomDrawLineWidth); RedPen.Freeze(); GreenPen.Freeze(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.PushGuidelineSet(new GuidelineSet(guidlinesX.ToArray(), guidlinesY.ToArray())); if (IsDrawingLine) { drawingContext.DrawGeometry(null, RedPen, positiveGroup); drawingContext.DrawGeometry(null, GreenPen, negativeGroup); } else { Brush white = Brushes.White; white.Freeze(); drawingContext.DrawGeometry(white, RedPen, positiveGroup); drawingContext.DrawGeometry(GreenBrush, GreenPen, negativeGroup); } drawingContext.Pop(); drawingContext.Close(); BitmapCache bc = new BitmapCache(); bc.SnapsToDevicePixels = true; bc.Freeze(); drawingVisual.CacheMode = bc; this.AddVisualChild(drawingVisual); }