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(); }
public void ApplyStyle(RadElement rootElement, bool isDynamicallyAddedElement) { //bool animationsEnabled = AnimatedPropertySetting.AnimationsEnabled; //AnimatedPropertySetting.AnimationsEnabled = false; //first should be applied selectors without any apply conditions LinkedList <NotAppliedSelector> selectorsWithConditions = new LinkedList <NotAppliedSelector>(); 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 (isDynamicallyAddedElement && selector is GeneralSelector) //{ // continue; //} if (selector.HasApplyCondition) { selectorsWithConditions.AddLast(new NotAppliedSelector(selector, group.PropertySettings)); } else { //Selector selects internally all applicable elements //selector.Apply(rootElement, group.PropertySettings); LinkedList <RadElement> selectedElements = selector.GetSelectedElements(rootElement); foreach (RadElement selected in selectedElements) { selector.Apply(selected, group.PropertySettings); } } } } foreach (NotAppliedSelector notApplied in selectorsWithConditions) { //Selector selects internally all applicable elements //notApplied.Selector.Apply(rootElement, notApplied.PropertySettings); foreach (RadElement selected in notApplied.Selector.GetSelectedElements(rootElement)) { notApplied.Selector.Apply(selected, notApplied.PropertySettings); } } //Temp optimization this.cachedChildrenHierarchyByElement.Clear(); }