private void VisualImage_Unloaded(object sender, RoutedEventArgs e)
 {
     try
     {
         ElementCompositionPreview.SetElementChildVisual(this, null);
         _backgroundBrush?.Dispose();
         //_foregroundBrush?.Dispose();
         BackgroundVisual?.Dispose();
         ForegroundVisual?.Dispose();
         ContainerVisual?.Dispose();
         //_uriSurface?.Dispose();
         _opacityAnimation?.Dispose();
     }
     catch
     {
         // ignored
     }
 }
Ejemplo n.º 2
0
        private void RenderBackground()
        {
            using (DrawingContext dc = BackgroundVisual.RenderOpen())
            {
                GuidelineSet guidelines = new GuidelineSet();
                guidelines.GuidelinesX.Add(0.0);
                guidelines.GuidelinesY.Add(0.0);
                dc.PushGuidelineSet(guidelines);

                dc.DrawRectangle(Brushes.White, null, new Rect(new Size(Width, Height)));

                if (IsGridVisible)
                {
                    for (double x = GridSize; x < Width; x += GridSize)
                    {
                        Pen pen = new Pen(Brushes.LightBlue, 1.0d);
                        if (x % (5 * GridSize) == 0)
                        {
                            pen = new Pen(Brushes.LightGray, 1.5d);
                        }
                        dc.DrawLine(pen, new Point(x, 0), new Point(x, Height));
                    }
                    for (double y = GridSize; y < Height; y += GridSize)
                    {
                        Pen pen = new Pen(Brushes.LightBlue, 1.0d);
                        if (y % (5 * GridSize) == 0)
                        {
                            pen = new Pen(Brushes.LightGray, 1.5d);
                        }
                        dc.DrawLine(pen, new Point(0, y), new Point(Width, y));
                    }
                }

                dc.Pop();
            }
        }