protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFAnnotationItem::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.SafeExec(() =>
            {
                if (dispose_count == 0)
                {
                    // Get rid of managed resources / get rid of cyclic references:
                    if (null != pdf_annotation)
                    {
                        pdf_annotation.Bindable.PropertyChanged -= pdf_annotation_PropertyChanged;
                    }

                    ButtonAnnotationDetails.MouseEnter  -= ButtonAnnotationDetails_MouseEnter;
                    ButtonAnnotationDetails.MouseLeave  -= ButtonAnnotationDetails_MouseLeave;
                    ButtonAnnotationDetails.MouseDown   -= ButtonAnnotationDetails_MouseDown;
                    TextAnnotationText.GotFocus         -= TextAnnotationText_GotFocus;
                    TextAnnotationText.LostFocus        -= TextAnnotationText_LostFocus;
                    TextAnnotationText.PreviewMouseDown -= TextAnnotationText_PreviewMouseDown;
                    TextAnnotationText.PreviewMouseMove -= TextAnnotationText_PreviewMouseMove;
                    TextAnnotationText.PreviewMouseUp   -= TextAnnotationText_PreviewMouseUp;

                    ObjTagEditorControl.GotFocus  -= ObjTagEditorControl_GotFocus;
                    ObjTagEditorControl.LostFocus -= ObjTagEditorControl_LostFocus;

                    ObjTagEditorControl.TagFeature_Add    = null;
                    ObjTagEditorControl.TagFeature_Remove = null;
                }
            });

            WPFDoEvents.SafeExec(() =>
            {
                // Clear the references for sanity's sake
                DataContext = null;
            });

            WPFDoEvents.SafeExec(() =>
            {
                pdf_annotation_layer       = null;
                pdf_annotation             = null;
                pdf_renderer_control_stats = null;

                pdf_annotation_editor_control_popup = null;
            });

            ++dispose_count;
        }
        public PDFAnnotationItem(PDFAnnotationLayer pdf_annotation_layer, PDFAnnotation pdf_annotation)
        {
            this.pdf_annotation_layer = new WeakReference <PDFAnnotationLayer>(pdf_annotation_layer);
            this.pdf_annotation       = pdf_annotation;

            DataContext = pdf_annotation.Bindable;

            InitializeComponent();

            MouseEnter += TextAnnotationText_MouseEnter;
            MouseLeave += TextAnnotationText_MouseLeave;

            ButtonAnnotationDetails.MouseEnter += ButtonAnnotationDetails_MouseEnter;
            ButtonAnnotationDetails.MouseLeave += ButtonAnnotationDetails_MouseLeave;
            ButtonAnnotationDetails.Cursor      = Cursors.Hand;
            ButtonAnnotationDetails.MouseDown  += ButtonAnnotationDetails_MouseDown;
            ButtonAnnotationDetails.Source      = Icons.GetAppIcon(Icons.Metadata);
            ButtonAnnotationDetails.Width       = 32;
            ButtonAnnotationDetails.ToolTip     = "Edit this annotation.";
            RenderOptions.SetBitmapScalingMode(ButtonAnnotationDetails, BitmapScalingMode.HighQuality);

            TextAnnotationText.Background        = Brushes.Transparent;
            TextAnnotationText.GotFocus         += TextAnnotationText_GotFocus;
            TextAnnotationText.LostFocus        += TextAnnotationText_LostFocus;
            TextAnnotationText.PreviewMouseDown += TextAnnotationText_PreviewMouseDown;
            TextAnnotationText.PreviewMouseMove += TextAnnotationText_PreviewMouseMove;
            TextAnnotationText.PreviewMouseUp   += TextAnnotationText_PreviewMouseUp;

            ObjTagEditorControl.GotFocus  += ObjTagEditorControl_GotFocus;
            ObjTagEditorControl.LostFocus += ObjTagEditorControl_LostFocus;

            pdf_annotation.Bindable.PropertyChanged += pdf_annotation_PropertyChanged;

            ObjTagEditorControl.TagFeature_Add    = Features.Document_AddAnnotationTag;
            ObjTagEditorControl.TagFeature_Remove = Features.Document_RemoveAnnotationTag;

            ReColor();

            //Unloaded += PDFAnnotationItem_Unloaded;
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }