Ejemplo n.º 1
0
        // Token: 0x06007C8D RID: 31885 RVA: 0x00230668 File Offset: 0x0022E868
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder)
        {
            UIElement uielement = attachedAnnotation.Parent as UIElement;

            if (component.PresentationContext != null)
            {
                return;
            }
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uielement);

            if (adornerLayer != null)
            {
                this.AddToAttachedAnnotations(attachedAnnotation, component);
                component.AddAttachedAnnotation(attachedAnnotation);
                AdornerPresentationContext.HostComponent(adornerLayer, component, uielement, reorder);
                return;
            }
            if (PresentationSource.FromVisual(uielement) == null)
            {
                return;
            }
            throw new InvalidOperationException(SR.Get("NoPresentationContextForGivenElement", new object[]
            {
                uielement
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add an attached annotation to a component and add the component to the adorner layer
        /// if the annotation component is not already in a presentation context.
        /// </summary>
        /// <param name="attachedAnnotation">the attachedAnnotation we are to add to the component</param>
        /// <param name="component">the component we are to add to the adorner layer</param>
        /// <param name="reorder">if true - the z-order must be reevaluated</param>
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder)
        {
            UIElement annotatedElement = attachedAnnotation.Parent as UIElement; // casted from DependencyObject

            Debug.Assert(annotatedElement != null, "the annotatedElement should inherit from UIElement");

            // if annotation component is already in presentation context, nothing else to do
            if (component.PresentationContext != null)
            {
                return;
            }

            // otherwise host in the appropriate adorner layer
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(annotatedElement); // note, GetAdornerLayer requires UIElement

            if (layer == null)
            {
                if (PresentationSource.FromVisual(annotatedElement) == null)
                {
                    // The annotated element is no longer part of the application tree.
                    // This probably means we are out of [....] - trying to add an annotation
                    // for an element that has already gone away.  Bug # 1580288 tracks
                    // the need to figure this out.
                    return;
                }

                throw new InvalidOperationException(SR.Get(SRID.NoPresentationContextForGivenElement, annotatedElement));
            }

            // add to the attachedAnnotations
            this.AddToAttachedAnnotations(attachedAnnotation, component);

            // let the annotation component know about the attached annotation
            // call add before adding to adorner layer so the component can be initialized
            component.AddAttachedAnnotation(attachedAnnotation); // this might cause recursion in modify if annotation component adds to annotation

            AdornerPresentationContext.HostComponent(layer, component, annotatedElement, reorder);
        }
        /// <summary> 
        /// Add an attached annotation to a component and add the component to the adorner layer
        /// if the annotation component is not already in a presentation context.
        /// </summary>
        /// <param name="attachedAnnotation">the attachedAnnotation we are to add to the component</param> 
        /// <param name="component">the component we are to add to the adorner layer</param>
        /// <param name="reorder">if true - the z-order must be reevaluated</param> 
        private void AddComponent(IAttachedAnnotation attachedAnnotation, IAnnotationComponent component, bool reorder) 
        {
            UIElement annotatedElement = attachedAnnotation.Parent as UIElement; // casted from DependencyObject 
            Debug.Assert(annotatedElement != null, "the annotatedElement should inherit from UIElement");

            // if annotation component is already in presentation context, nothing else to do
            if (component.PresentationContext != null) return; 

            // otherwise host in the appropriate adorner layer 
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(annotatedElement); // note, GetAdornerLayer requires UIElement 
            if (layer == null)
            { 
                if (PresentationSource.FromVisual(annotatedElement) == null)
                {
                    // The annotated element is no longer part of the application tree.
                    // This probably means we are out of [....] - trying to add an annotation 
                    // for an element that has already gone away.  Bug # 1580288 tracks
                    // the need to figure this out. 
                    return; 
                }
 
                throw new InvalidOperationException(SR.Get(SRID.NoPresentationContextForGivenElement, annotatedElement));
            }

            // add to the attachedAnnotations 
            this.AddToAttachedAnnotations(attachedAnnotation, component);
 
            // let the annotation component know about the attached annotation 
            // call add before adding to adorner layer so the component can be initialized
            component.AddAttachedAnnotation(attachedAnnotation); // this might cause recursion in modify if annotation component adds to annotation 

            AdornerPresentationContext.HostComponent(layer, component, annotatedElement, reorder);

        }