public void ProcessStyle(RadElement rootElement, bool isDynamicallyAddedElement) { PrepareCache(rootElement); for (int i = 0; i < this.PropertySettingGroups.Count; i++) { PropertySettingGroup group = this.PropertySettingGroups[i]; group.SetIsFromStyleSheet(); for (int k = 0; k < group.Selectors.Count; k++) { IElementSelector selector = group.Selectors[k]; if (selector is HierarchicalSelector) { ((HierarchicalSelector)selector).SetCache(this.cachedChildrenHierarchyByElement); } //if (isDynamicallyAddedElement && selector is GeneralSelector) //{ // continue; //} LinkedList <RadElement> selectedElements = selector.GetSelectedElements(rootElement); foreach (RadElement selected in selectedElements) { selected.AddRangeBehavior(selector.GetBehaviors(group)); selected.RoutedEventBehaviors.AddRange(selector.GetRoutedEventBehaviors(group)); } } } }
public virtual void Unapply(RadElement radElement) { if (cachedChildrenHierarchyByElement.Count == 0) { PrepareCache(radElement); } for (int i = 0; i < this.PropertySettingGroups.Count; i++) { PropertySettingGroup group = this.PropertySettingGroups[i]; for (int k = 0; k < group.Selectors.Count; k++) { IElementSelector selector = group.Selectors[k]; if (selector is HierarchicalSelector) { ((HierarchicalSelector)selector).SetCache(this.cachedChildrenHierarchyByElement); } LinkedList <RadElement> selectedElements = selector.GetSelectedElements(radElement); foreach (RadElement selected in selectedElements) { selector.Unregister(selected, group.PropertySettings); } } } for (int i = 0; i < this.PropertySettingGroups.Count; i++) { PropertySettingGroup group = this.PropertySettingGroups[i]; for (int k = 0; k < group.Selectors.Count; k++) { IElementSelector selector = group.Selectors[k]; LinkedList <RadElement> selectedElements = selector.GetSelectedElements(radElement); foreach (RadElement selected in selectedElements) { PropertyChangeBehaviorCollection propertyChangeBehaviors = selector.GetBehaviors(group); for (int behaviorIndex = 0; behaviorIndex < propertyChangeBehaviors.Count; behaviorIndex++) { PropertyChangeBehavior toRemove = propertyChangeBehaviors[behaviorIndex]; toRemove.BehaviorRemoving(selected); } RoutedEventBehaviorCollection routedEventBehaviors = selector.GetRoutedEventBehaviors(group); for (int eventIndex = 0; eventIndex < routedEventBehaviors.Count; eventIndex++) { RoutedEventBehavior routedEventBehavior = routedEventBehaviors[eventIndex]; routedEventBehavior.BehaviorRemoving(selected); } selected.RemoveRangeBehaviors(propertyChangeBehaviors); selected.RemoveRangeRoutedEventBehaviors(routedEventBehaviors); } } } this.cachedChildrenHierarchyByElement.Clear(); }