Detach() public method

Detaches this adorner from the adorned element
public Detach ( ) : void
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Detaches this adorner from the adorned element
        /// </summary>
        public void Detach()
        {
            if (childAdorner != null)
            {
                childAdorner.Detach();
            }
            if (!attached)
            {
                return;
            }


            Log("Detach Begin");

            // Remove window hookup
            if ((attachedHwndSource != null) && (!attachedHwndSource.IsDisposed))
            {
                // Crashes in a few time if invoke immediately ???
                AdornedElement.Dispatcher.BeginInvoke((System.Threading.ThreadStart) delegate { attachedHwndSource.RemoveHook(WindowProc); });
            }

            // Maybe adorner awaiting attaching, cancel it
            oneOfAssociatedElements.Loaded -= OnDelayAttach;

            if (focusedElement != null)
            {
                focusedElement.LostKeyboardFocus -= OnFocusLost;
                focusedElement.PreviewKeyDown    -= OnPreviewKeyDown;
                focusedElement.PreviewTextInput  -= this.OnFocusedElementPreviewTextInput;
                focusedElement = null;
            }

            GetTopLevelElement(oneOfAssociatedElements).PreviewMouseDown -= OnInputActionOccured;

            // Show this adorner
            adornerLayer.Remove(this);
            // Clears previous user input
            enteredKeys = "";
            attached    = false;

            // Stop timer to track focus changing
            timerFocusTracking.Stop();

            Log("Detach End");
        }