public PropertySettingGroup Deserialize() { PropertySettingGroup group = new PropertySettingGroup(); group.BasedOn = this.basedOn; if (this.propertySettings != null) { for (int settingIndex = 0; settingIndex < this.PropertySettings.Count; settingIndex++) { XmlPropertySetting xmlPropertySetting = this.PropertySettings[settingIndex]; IPropertySetting setting = xmlPropertySetting.Deserialize(); group.PropertySettings.Add(setting); } } if (this.selectors != null) { for (int selectorIndex = 0; selectorIndex < this.Selectors.Count; selectorIndex++) { XmlElementSelector xmlSelector = this.Selectors[selectorIndex]; IElementSelector selector = xmlSelector.Deserialize(); group.Selectors.Add(selector); } } return(group); }
public void DeserializePropertySettingGroups(PropertySettingGroupCollection resGroups) { for (int i = 0; i < this.PropertySettingGroups.Count; i++) { XmlPropertySettingGroup xmlGroup = this.PropertySettingGroups[i]; if (xmlGroup.PropertySettings == null || xmlGroup.Selectors == null) { continue; } try { PropertySettingGroup group = xmlGroup.Deserialize(); resGroups.Add(group); } catch (Exception ex) { string message = "Exception occured while deserializing PropertySettingGroup: " + ex.ToString(); Trace.WriteLine(message); Debug.Fail(message); } } }
private void ApplyChildVisualStateSelector( IStylableElement stylable, PropertySettingGroup group) { foreach (RadObject testElement in stylable.ChildrenHierarchy) { if (group.Selector.ChildSelector.Type == ElementSelectorTypes.VisualStateSelector) { IStylableElement stylableElement = testElement as IStylableElement; if (stylableElement != null) { bool flag = false; foreach (string stateFallback in this.GetStateFallbackList(stylableElement)) { if (group.Selector.ChildSelector.IsValid(testElement, stateFallback)) { stylableElement.ApplySettings(group); flag = true; break; } } if (flag) { break; } } } else if (group.Selector.ChildSelector.IsValid(testElement, string.Empty)) { (testElement as IStylableNode).ApplySettings(group); break; } } }
public PropertySettingGroup Deserialize() { PropertySettingGroup propertySettingGroup = new PropertySettingGroup(); propertySettingGroup.BasedOn = this.basedOn; if (this.propertySettings != null) { for (int index = 0; index < this.PropertySettings.Count; ++index) { IPropertySetting propertySetting = this.PropertySettings[index].Deserialize(); if (propertySetting is PropertySetting) { propertySettingGroup.PropertySettings.Add(propertySetting as PropertySetting); } } } if (this.selectors != null) { for (int index = 0; index < this.Selectors.Count; ++index) { IElementSelector internalSelector = this.Selectors[index].Deserialize(); propertySettingGroup.Selector = (ElementSelector) new WrapSelector(internalSelector); } } return(propertySettingGroup); }
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 PropertySettingGroup(PropertySettingGroup sourceGroup) : this() { this.basedOn = sourceGroup.basedOn; foreach (PropertySetting propertySetting in sourceGroup.PropertySettings) { this.PropertySettings.Add(new PropertySetting(propertySetting)); } this.selector = new ElementSelector(sourceGroup.Selector); }
public virtual PropertyChangeBehaviorCollection GetBehaviors( PropertySettingGroup group) { if (this.createdPropertyChangeBehaviors == null) { if (this.condition != null) { throw new NotImplementedException(); } this.createdPropertyChangeBehaviors = new PropertyChangeBehaviorCollection(); } return(this.createdPropertyChangeBehaviors); }
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(); }
private void ReadPropertySettingGroup(ReaderContext context, XmlTextReader reader) { PropertySettingGroup propertySettingGroup = new PropertySettingGroup(); while (reader.MoveToNextAttribute()) { if (reader.Name == "BasedOn") { propertySettingGroup.BasedOn = reader.Value; break; } } context.currentStyleGroup.PropertySettingGroups.Add(propertySettingGroup); context.currentSettingGroup = propertySettingGroup; }
public void AssociateWithRepositoryItem(string key) { if (string.IsNullOrEmpty(key) || this.IsBasedOnRepositoryItem(key)) { return; } if (string.IsNullOrEmpty(this.basedOn)) { this.basedOn = key; } else { PropertySettingGroup propertySettingGroup = this; propertySettingGroup.basedOn = propertySettingGroup.basedOn + (object)',' + key; } }
public XmlPropertySettingGroup(PropertySettingGroup group) { foreach (PropertySetting propertySetting in group.PropertySettings) { string fullName; if (propertySetting.Property != null) { fullName = propertySetting.Property.FullName; } else if (!string.IsNullOrEmpty(propertySetting.FullName)) { fullName = propertySetting.FullName; } else { continue; } if (propertySetting.EndValue != null) { XmlAnimatedPropertySetting animatedPropertySetting = new XmlAnimatedPropertySetting(); animatedPropertySetting.Property = fullName; animatedPropertySetting.Value = propertySetting.Value; animatedPropertySetting.EndValue = propertySetting.EndValue; this.PropertySettings.Add((XmlPropertySetting)animatedPropertySetting); } else { this.PropertySettings.Add(new XmlPropertySetting() { Property = fullName, Value = propertySetting.Value }); } } if (group.Selector != null) { this.Selectors.Add(this.CreateSelector(group.Selector)); } if (!string.IsNullOrEmpty(group.BasedOn)) { this.basedOn = group.BasedOn; } else { this.basedOn = (string)null; } }
public virtual RoutedEventBehaviorCollection GetRoutedEventBehaviors(PropertySettingGroup group) { if (this.createdRoutedEventsBehaviors == null) { this.createdRoutedEventsBehaviors = new RoutedEventBehaviorCollection(); if (this.condition != null) { foreach (RaisedRoutedEvent routedEvent in Condition.AffectedEvents) { RoutedEventStyleBehavior behavior = new RoutedEventStyleBehavior(routedEvent, this, group.PropertySettings); this.createdRoutedEventsBehaviors.Add(behavior); } } } return(this.createdRoutedEventsBehaviors); }
public XmlRepositoryItem[] GetRepositoryItems(XmlStyleRepository repository, PropertySettingGroup group) { string[] keys = group.GetBasedOnRepositoryItems(); List <XmlRepositoryItem> items = new List <XmlRepositoryItem>(); foreach (string key in keys) { foreach (XmlRepositoryItem item in repository.RepositoryItems) { if (item.Key == key) { items.Add(item); } } } return(items.ToArray()); }
private bool ApplySimpleSelectorToChildren( IStylableNode stylable, PropertySettingGroup group, ElementSelector selector) { foreach (RadObject child in stylable.Children) { if (selector.IsCompatible(child)) { (child as IStylableNode).ApplySettings(group); return(true); } if (this.ApplySimpleSelectorToChildren(child as IStylableNode, group, selector)) { return(true); } } return(false); }
//Method supports old theming infrastructure and will be depricated public virtual PropertyChangeBehaviorCollection GetBehaviors(PropertySettingGroup group) { if (this.createdPropertyChangeBehaviors == null) { if (this.condition != null) { this.createdPropertyChangeBehaviors = new PropertyChangeBehaviorCollection(condition.AffectedProperties.Count); for (int i = 0; i < condition.AffectedProperties.Count; i++) { RadProperty property = condition.AffectedProperties[i]; PropertyChangeStyleBehavior behavior = new PropertyChangeStyleBehavior(property, this, group.PropertySettings); this.createdPropertyChangeBehaviors.Add(behavior); } } else { this.createdPropertyChangeBehaviors = new PropertyChangeBehaviorCollection(); } } return(createdPropertyChangeBehaviors); }
private Theme Parse(CSSParser parser) { Theme theme = new Theme(); theme.StyleGroups.Add(new StyleGroup()); foreach (CSSGroup group in parser.groups) { if (group.name == "theme") { theme.Name = group["name"].value; StyleRegistration styleRegistration = new StyleRegistration(); theme.StyleGroups[0].Registrations.Add(styleRegistration); if (group.Contains("elementType")) { styleRegistration.RegistrationType = "ElementTypeDefault"; styleRegistration.ElementType = group["elementType"].value; } if (group.Contains("controlType")) { styleRegistration.RegistrationType = "ElementTypeControlType"; styleRegistration.ControlType = group["controlType"].value; styleRegistration.ElementType = "Telerik.WinControls.RootRadElement"; } } else if (group.name.StartsWith("#")) { StyleRepository styleRepository = new StyleRepository(); styleRepository.Key = group.name.Remove(0, 1).Trim(); foreach (CSSItem cssItem in group.items) { PropertySetting propertySetting = this.CreatePropertySetting(cssItem); styleRepository.Settings.Add(propertySetting); } theme.Repositories.Add(styleRepository); } else { PropertySettingGroup propertySettingGroup = new PropertySettingGroup(); if (group.BasedOn.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); for (int index = 0; index < group.BasedOn.Count; ++index) { string str = group.BasedOn[index]; stringBuilder.Append(str); if (index < group.BasedOn.Count - 1) { stringBuilder.Append(","); } } propertySettingGroup.BasedOn = stringBuilder.ToString(); } propertySettingGroup.Selector = new ElementSelector(); propertySettingGroup.Selector.Type = ElementSelectorTypes.VisualStateSelector; propertySettingGroup.Selector.Value = group.name; if (!string.IsNullOrEmpty(group.childName)) { propertySettingGroup.Selector.ChildSelector = new ElementSelector(group.childName); propertySettingGroup.Selector.ChildSelector.IsRecursive = true; } theme.StyleGroups[0].PropertySettingGroups.Add(propertySettingGroup); foreach (CSSItem cssItem in group.items) { if (cssItem.name == "selectChild") { propertySettingGroup.Selector.ChildSelector = new ElementSelector(ElementSelectorTypes.VisualStateSelector, cssItem.value); propertySettingGroup.Selector.ChildSelector.IsRecursive = true; } else { if (cssItem.name == "selectChildClass") { propertySettingGroup.Selector.ChildSelector = new ElementSelector(ElementSelectorTypes.ClassSelector, cssItem.value); } PropertySetting propertySetting = this.CreatePropertySetting(cssItem); propertySettingGroup.PropertySettings.Add(propertySetting); } } } } return(theme); }
/// <summary> /// This method supports TPF infrastructure and is intended for internal use only. /// </summary> /// <param name="applyUnconditional"></param> /// <param name="groups"></param> /// <returns></returns> public StyleSheet GetStyleSheet(XmlSelectorBase applyUnconditional, XmlPropertySettingGroup[] groups) { StyleSheet res = new StyleSheet(); SelectorBase applySelector = null; if (this.PropertySettingGroups == null) { return(res); } for (int i = 0; i < this.PropertySettingGroups.Count; i++) { XmlPropertySettingGroup xmlGroup = this.PropertySettingGroups[i]; if (xmlGroup.Selectors != null) { for (int selectorIndex = 0; selectorIndex < xmlGroup.Selectors.Count; selectorIndex++) { XmlElementSelector xmlSelector = xmlGroup.Selectors[selectorIndex]; if (xmlSelector == applyUnconditional) { applySelector = (SelectorBase)xmlSelector.Deserialize(); break; } } } } for (int i = 0; i < this.PropertySettingGroups.Count; i++) { XmlPropertySettingGroup xmlGroup = this.PropertySettingGroups[i]; PropertySettingGroup group = new PropertySettingGroup(); if (xmlGroup.PropertySettings == null || xmlGroup.Selectors == null) { continue; } bool disable = false; if (applyUnconditional != null) { for (int groupIndex = 0; groupIndex < groups.Length; groupIndex++) { XmlPropertySettingGroup g = groups[groupIndex]; if (g == xmlGroup) { disable = true; break; } } } for (int settingIndex = 0; settingIndex < xmlGroup.PropertySettings.Count; settingIndex++) { XmlPropertySetting xmlPropertySetting = xmlGroup.PropertySettings[settingIndex]; IPropertySetting setting = xmlPropertySetting.Deserialize(); group.PropertySettings.Add(setting); } //IElementSelector activeSelector = null; for (int selectorIndex = 0; selectorIndex < xmlGroup.Selectors.Count; selectorIndex++) { XmlElementSelector xmlSelector = xmlGroup.Selectors[selectorIndex]; IElementSelector selector = null; selector = xmlSelector.Deserialize(); if (xmlSelector == applyUnconditional) { applySelector.IsActiveSelectorInStyleBuilder = true; selector = applySelector; //continue; } else if (disable) { ((SelectorBase)selector).DisableStyle = true; //((SelectorBase)selector).ExcludeSelector = applySelector; } group.Selectors.Add(selector); } //if (activeSelector != null) // group.Selectors.Insert(0, activeSelector); res.PropertySettingGroups.Add(group); } return(res); }