示例#1
0
        private void ElementStyleChanged(RadElement element, RadPropertyChangedEventArgs changeArgs)
        {
            StyleMap styleMap;

            this.styleElementMap.TryGetValue(element.GetHashCode(), out styleMap);

#if DEBUG
            if (changeArgs.NewValue != null && element.IsThemeApplied)
            {
                for (RadElement toTest = element.Parent; toTest != null; toTest = toTest.Parent)
                {
                    if (!toTest.IsThemeApplied ||
                        !toTest.PropagateStyleToChildren)
                    {
                        break;
                    }

                    //Parent Style alredy set
                    if (toTest.Style != null)
                    {
                        StyleMap parentStyleMap = null;
                        this.styleElementMap.TryGetValue(toTest.GetHashCode(), out parentStyleMap);
                        if (styleMap != null)
                        {
                            styleMap.OnElementRemoved(element);
                        }
                        else if (this.state != StyleManagerState.Attaching)
                        {
                            Debug.Fail("Unknown Style instance found");
                        }
                    }
                }
            }
#endif

            if (changeArgs.NewValue == null)
            {
                if (styleMap != null)
                {
                    styleMap.SetStyleSheet(null);
                    this.styleElementMap.Remove(element.GetHashCode());
                }
            }
            else
            {
                if (styleMap == null)
                {
                    styleMap = new StyleMap(this, (StyleSheet)changeArgs.NewValue, element);
                    this.styleElementMap.Add(element.GetHashCode(), styleMap);
                }
                else
                {
                    styleMap.SetStyleSheet((StyleSheet)changeArgs.NewValue);
                }
            }
        }
示例#2
0
        public override void ApplyValue(RadElement element)
        {
            if (this.ApplyDelay > 0)
            {
                //we have an initial delay that we should reflect
                Timer timer = new Timer();
                timer.Interval = this.ApplyDelay;
                timer.Tick    += new EventHandler(delayTimer_Tick);
                timer.Tag      = element;

                delayTimerForElement[element.GetHashCode()] = timer;
                timer.Start();

                object animatedValue = this.StartValue;
                if (animatedValue != null)
                {
                    ElementValuesAnimator animator = this.GetAnimator(element);
                    animator.SetCurrentValue(animatedValue);
                    this.OnAnimationStarted(new AnimationStatusEventArgs(element, false));
                }
            }
            else
            {
                ApplyValueInternal(element);
            }
        }
示例#3
0
        public void ApplyStyleToVirtualElement(RadElement element)
        {
            if (!element.IsInValidState(false))
            {
                return;
            }

            if (!element.PropagateStyleToChildren || element.IsThemeRefreshSuspended)
            {
                return;
            }

            if (this.state == StyleManagerState.Detaching || this.state == StyleManagerState.Detached)
            {
                return;
            }

            ComponentThemableElementTree oldTree = element.ElementTree;

            element.UpdateReferences(this.owner.ElementTree, false, true);

            this.MapStylesToElementsRecursive(element);

            bool     parentNotPropagateStyleToChildren;
            StyleMap map = this.FindStyleMapForElement(element, out parentNotPropagateStyleToChildren);

            if (map != null)
            {
                if (this.styleElementMap.ContainsKey(element.GetHashCode()))
                {
                    this.styleElementMap.Remove(element.GetHashCode());
                }
                else
                {
                    map.BuildStyle();
                    map.SetStyleSheet(element.ComposeStyle());
                }
                map.OnElementRemoved(element);
            }

            element.UpdateReferences(oldTree, false, true);
        }
示例#4
0
        internal bool RemoveDelayTimer(RadElement element)
        {
            int   elementID  = element.GetHashCode();
            Timer delayTimer = (Timer)this.delayTimerForElement[elementID];

            if (delayTimer == null)
            {
                return(false);
            }

            this.delayTimerForElement.Remove(elementID);
            delayTimer.Stop();
            delayTimer.Dispose();

            return(true);
        }
示例#5
0
        private void delayTimer_Tick(object sender, EventArgs e)
        {
            Timer timer = (Timer)sender;

            timer.Stop();
            timer.Dispose();
            RadElement element = (RadElement)timer.Tag;

            int    elementID = element.GetHashCode();
            object res       = delayTimerForElement[elementID];

            if (res != null)
            {
                delayTimerForElement.Remove(elementID);
                this.ApplyValueInternal(element);
            }
        }
示例#6
0
        protected StyleMap MapStyleToElement(RadElement element)
        {
            //reset any style
            element.Style = null;

            StyleBuilder builder = ThemeResolutionService.GetStyleSheetBuilder(element);

            if (builder == null)
            {
                return(null);
            }

            StyleMap styleMap = new StyleMap(this, builder, element);

            this.styleElementMap[element.GetHashCode()] = styleMap;

            return(styleMap);
        }
示例#7
0
        internal void RemoveStyleOwner(RadElement element)
        {
            int      hashCode = element.GetHashCode();
            StyleMap map;

            styleElementMap.TryGetValue(hashCode, out map);
            Debug.Assert(map != null, "Invalid style mapping for element " + element);

            if (this.styleMapCleanUpLock > 0)
            {
                //do not clean-up style map, simply detach all elements
                map.StylesheetTree.DetachElement(element);
            }
            else
            {
                map.UnapplyStyle();
                this.styleElementMap.Remove(hashCode);
            }
        }
示例#8
0
        public void ReApplyStyle(RadElement radElement, bool traverseElementTree)
        {
            if (this.state != StyleManagerState.Attached || this.styleElementMap.Count == 0)
            {
                return;
            }

            if (!this.ShouldProcessElement(radElement))
            {
                return;
            }

            bool     parentNotPropagateStyleToChildren;
            StyleMap styleMap = this.FindStyleMapForElement(radElement, out parentNotPropagateStyleToChildren);

            if (styleMap != null)
            {
                styleMap.RemapElement(radElement);
            }

            if (traverseElementTree)
            {
                int elementHash = radElement.GetHashCode();
                foreach (KeyValuePair <int, StyleMap> mapEntry in this.styleElementMap)
                {
                    if (elementHash == mapEntry.Key)
                    {
                        continue;
                    }

                    if (radElement.IsAncestorOf(mapEntry.Value.StyleRootElement))
                    {
                        mapEntry.Value.RemapElement(null);
                    }
                }
            }
        }
示例#9
0
        private StyleMap FindStyleMapForElement(RadElement radElement, out bool parentNotPropagateStyleToChildren)
        {
            parentNotPropagateStyleToChildren = false;
            StyleMap styleMap = null;

            for (RadElement toTest = radElement; toTest != null; toTest = toTest.Parent)
            {
                if (!toTest.PropagateStyleToChildren)
                {
                    parentNotPropagateStyleToChildren = true;
                    break;
                }

                if (toTest.Style == null)
                {
                    continue;
                }

                this.styleElementMap.TryGetValue(toTest.GetHashCode(), out styleMap);
                break;
            }

            return(styleMap);
        }