using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PDF_Office.CustomControl { internal class CustomImageControl : FrameworkElement { private DrawingVisual PresentChild { get; set; } private DrawingContext DrawDC { get; set; } public CustomImageControl() { PresentChild = new DrawingVisual(); AddVisualChild(PresentChild); AddLogicalChild(PresentChild); } protected override Visual GetVisualChild(int index) { if (PresentChild == null) { throw new ArgumentOutOfRangeException(); } return PresentChild; } protected override int VisualChildrenCount { get { if (PresentChild != null) { return 1; } return 0; } } public DrawingContext OpenDraw() { if (DrawDC == null) { DrawDC = PresentChild?.RenderOpen(); } return DrawDC; } public void CloseDraw() { DrawDC?.Close(); DrawDC = null; } } }