Пример #1
0
            public FocusVisualAdorner(ContentElement adornedElement, UIElement adornedElementParent, IContentHost contentHostParent, Style focusVisualStyle)
                : base(adornedElementParent)
            {
                Debug.Assert(adornedElement != null, "adornedElement should not be null");
                Debug.Assert(adornedElementParent != null, "adornedElementParent should not be null");
                Debug.Assert(contentHostParent != null, "contentHostParent should not be null");
                Debug.Assert(contentHostParent is Visual, "contentHostParent should be Visual");
                Debug.Assert(focusVisualStyle != null, "focusVisual should not be null");

                _contentHostParent = contentHostParent;
                _adornedContentElement = adornedElement;
                _focusVisualStyle = focusVisualStyle;

                Canvas canvas = new Canvas();
                _canvasChildren = canvas.Children;
                _adorderChild = canvas;
                AddVisualChild(_adorderChild);

                IsClipEnabled = true;
                IsHitTestVisible = false;
                IsEnabled = false;
            }
Пример #2
0
        private static UIElement GetParentUIElementFromContentElement(ContentElement ce, ref IContentHost ichParent)
        {
            if (ce == null)
                return null;

            IContentHost ich = MS.Internal.Documents.ContentHostHelper.FindContentHost(ce);
            if (ichParent == null)
                ichParent = ich;

            DependencyObject parent =  ich as DependencyObject;
            if(parent != null)
            {
                // Case 1: UIElement
                // return the element
                UIElement eParent = parent as UIElement;
                if(eParent != null)
                    return eParent;

                // Case 2: Visual
                // Walk up the visual tree until we find UIElement
                Visual visualParent = parent as Visual;
                while (visualParent != null)
                {
                    visualParent = VisualTreeHelper.GetParent(visualParent) as Visual;
                    UIElement uielement = visualParent as UIElement;
                    if (uielement != null)
                        return uielement;
                }

                // Case 3: ContentElement
                ContentElement ceParent = parent as ContentElement;
                if(ceParent != null)
                    return GetParentUIElementFromContentElement(ceParent, ref ichParent);
            }

            return null;
        }
Пример #3
0
        internal void AddHighPriority(IContentHost host)
        {
            lock (_sync)
            {
                if (_manager == null)
                    throw new ObjectDisposedException("this");
                if (host == null)
                    throw new ArgumentNullException();
                if (_nullReferences.Count > 0)
                {
                    WeakReference wr = _nullReferences.Pop();
                    wr.Target = host;
                    _highPriorityItems.Add(wr);
                }
                else
                    _highPriorityItems.Add(new WeakReference(host));

                if (_created)
                    host.LoadContent(this, _manager);

                ProcessDelayed();
            }
        }
Пример #4
0
 /// <summary>
 ///   Unregister an <see cref = "IContentHost" /> instance with this content manager. NOTE: Instances are stored by weak reference and do not need to be manually removed (see remarks)
 /// </summary>
 /// <remarks>
 ///   <para>Instances are stored by weak reference, so this method should only be called when removing the object early is desired.</para>
 ///   <para>Instances will not be kept alive when added, and do not need to be removed to make sure they are garbage collected</para>
 /// </remarks>
 /// <param name = "host"></param>
 public void Remove(IContentHost host)
 {
     if (Monitor.TryEnter(_sync))
     {
         try
         {
             foreach (WeakReference wr in _items.Where(wr => wr.Target == host))
             {
                 if (_items.Count > 1)
                 {
                     wr.Target = _items[_items.Count - 1].Target;
                     _items[_items.Count - 1].Target = null;
                 }
                 else
                     wr.Target = null;
                 break;
             }
             _nullReferences.Push(_items[_items.Count - 1]);
             _items.RemoveAt(_items.Count - 1);
         }
         finally
         {
             Monitor.Exit(_sync);
         }
     }
     else
     {
         lock (_delayedRemoveList)
             _delayedRemoveList.Add(host);
     }
 }
Пример #5
0
        /// <summary>
        ///   Register an <see cref = "IContentHost" /> instance with this content manager
        /// </summary>
        /// <param name = "host"></param>
        public void Add(IContentHost host)
        {
            if (Monitor.TryEnter(_sync))
            {
                try
                {
                    if (_manager == null)
                        throw new ObjectDisposedException("this");
                    if (host == null)
                        throw new ArgumentNullException();
                    if (_nullReferences.Count > 0)
                    {
                        WeakReference wr = _nullReferences.Pop();
                        wr.Target = host;
                        _items.Add(wr);
                    }
                    else
                        _items.Add(new WeakReference(host));

                    if (_created)
                        host.LoadContent(this, _manager);
                }
                finally
                {
                    Monitor.Exit(_sync);
                }
            }
            else
            {
                lock (_delayedAddList)
                    _delayedAddList.Add(host);
            }
        }
Пример #6
0
 /// <summary>
 ///   Register an <see cref = "IContentHost" /> instance with this content manager
 /// </summary>
 /// <param name = "host"></param>
 public void PreLoad(IContentHost host)
 {
     if (!LoadingComplete && !LoadingInProgress)
     {
         ContentToLoad.Add(host);
     }
     else
     {
         Content.Add(host);
     }
 }
Пример #7
0
         //only one will be returned, whichever found first
        internal void GetUIParentOrICH(out UIElement uiParent, out IContentHost ich)
        {
            ich = null;
            uiParent = null;

            for(Visual v = VisualTreeHelper.GetParent(this) as Visual; v != null; v = VisualTreeHelper.GetParent(v) as Visual)
            {
                ich = v as IContentHost;
                if (ich != null) break;

                if(v.CheckFlagsAnd(VisualFlags.IsUIElement))
                {
                    uiParent = (UIElement)v;
                    break;
                }
            }
        }