Exemple #1
0
        /// <summary>
        /// Update the Adorners for the given element
        /// </summary>
        /// <param name="element">UIElement for which we're updating AdornerSet</param> 
        private void UpdateElementAdorners(UIElement element)
        { 
            Size size; 

            // we intentionally do not ascend in to a 3D scene 
            Visual adornerLayerParent = VisualTreeHelper.GetParent(this) as Visual;
            if (adornerLayerParent == null)
            {
                return; 
            }
 
            Debug.Assert(element != null); 
            ArrayList adornerInfos = ElementMap[element] as ArrayList;
            if (adornerInfos == null) 
            {
                return;
            }
 
            bool dirty = false;
 
            // 
            // See if the adorners need to be rerendered due to object resizing
            // 
            GeneralTransform transform = element.TransformToAncestor(adornerLayerParent);

            for (int i = 0; i < adornerInfos.Count; i++)
            { 
                AdornerInfo adornerInfo = (AdornerInfo)adornerInfos[i];
                size = element.RenderSize; 
                Geometry clip = null; 
                bool clipChanged = false;
                if (adornerInfo.Adorner.IsClipEnabled) 
                {
                    clip = GetClipGeometry(adornerInfo.Adorner.AdornedElement, adornerInfo.Adorner);
                    if (adornerInfo.Clip == null && clip != null || adornerInfo.Clip != null && clip == null ||
                     (adornerInfo.Clip != null && clip != null && adornerInfo.Clip.Bounds != clip.Bounds)) 
                    {
                        clipChanged = true; 
                    } 
                }
 
                if (adornerInfo.Adorner.NeedsUpdate(adornerInfo.RenderSize) || adornerInfo.Transform == null ||
                    transform.AffineTransform == null || adornerInfo.Transform.AffineTransform == null ||
                    transform.AffineTransform.Value != adornerInfo.Transform.AffineTransform.Value ||
                    clipChanged) 
                {
                    InvalidateAdorner(adornerInfo); 
                    adornerInfo.RenderSize = size; 
                    adornerInfo.Transform = transform;
                    if (adornerInfo.Adorner.IsClipEnabled) 
                    {
                        adornerInfo.Clip = clip;
                    }
                    dirty = true; 
                }
            } 
 
            if (dirty)
                InvalidateMeasure(); 
        }