예제 #1
0
        public void OnElementSelectorKeyChanged(RadElement element, RadPropertyChangedEventArgs changeArgs)
        {
            if (changeArgs.Property == RadItem.VisualStateProperty && !this.hasVisualSelectors)
            {
                return;
            }

            string oldSelectorValue = changeArgs.OldValue as string;
            int    oldSelectorKey   = -1;

            Debug.Assert(oldSelectorValue != null);

            //TODO: decouple
            if (changeArgs.Property == RadElement.ClassProperty)
            {
                oldSelectorKey = ClassSelector.GetSelectorKey(oldSelectorValue);
            }
            else if (changeArgs.Property == RadItem.VisualStateProperty)
            {
                oldSelectorKey = VisualStateSelector.GetSelectorKey(oldSelectorValue);
            }

            IEnumerable <StylesheetTreeNode> nodeList = null;

            if (oldSelectorKey != -1)
            {
                //Optimization
                LinkedList <StylesheetTreeNode> mappedNodes;
                if (this.nodesByKey.TryGetValue(oldSelectorKey, out mappedNodes))
                {
                    nodeList = mappedNodes;
                }
            }
            else
            {
                nodeList = this.RootNode.Nodes;
            }

            if (nodeList != null)
            {
                //TODO: optimization possible
                //Detach element should traverse the element tree and prepare cache for AttachElement call later
                foreach (StylesheetTreeNode node in nodeList)
                {
                    node.DetachElement(element);
                }
            }

            this.AttachElement(element);
        }
        public ICollection <StylesheetTreeNode> FindNodes(RadElement element)
        {
            //TODO too coupled to RadElement and its properties
            LinkedList <StylesheetTreeNode> result = new LinkedList <StylesheetTreeNode>();

            if (nodes == null)
            {
                return(result);
            }

            RadItem            item = element as RadItem;
            StylesheetTreeNode foundNode;

            if (item != null && item.StateManager != null /*&& !string.IsNullOrEmpty(item.VisualState)*/)
            {
                //Opptimization for Old themes
                if (this.hasVisualStateSelectors)
                {
                    foreach (string itemState in item.StateManager.GetStateFallbackList(item))
                    {
                        if (this.nodes.TryGetValue(VisualStateSelector.GetSelectorKey(itemState), out foundNode))
                        {
                            result.AddLast(foundNode);
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(element.Class))
            {
                if (this.nodes.TryGetValue(ClassSelector.GetSelectorKey(element.Class), out foundNode))
                {
                    result.AddLast(foundNode);
                }
            }

            if (!string.IsNullOrEmpty(element.Name) && this.nodes.TryGetValue(NameSelector.GetSelectorKey(element.Name), out foundNode))
            {
                result.AddLast(foundNode);
            }

            if (this.nodes.TryGetValue(element.GetThemeEffectiveType().GetHashCode(), out foundNode))
            {
                result.AddLast(foundNode);
            }

            return(result);
        }