private LinkedList <string> GetStateFallbackList(IStylableElement item) { LinkedList <string> linkedList = new LinkedList <string>(); string visualState = item.VisualState; if (string.IsNullOrEmpty(visualState)) { return(linkedList); } string[] strArray = visualState.Split('.'); if (strArray.Length < 2) { linkedList.AddLast(visualState); return(linkedList); } for (int index = strArray.Length - 1; index > 0; --index) { for (int startIndex = 1; startIndex <= index; ++startIndex) { linkedList.AddLast(item.ThemeRole + "." + string.Join(".", strArray, startIndex, index - startIndex + 1)); } } linkedList.AddLast(strArray[0]); return(linkedList); }
public void ApplyThemeToElement(RadObject element, bool recursive) { if (this.ComponentTreeHandler.Initializing) { return; } this.EnsureTheme(); if (this.theme == null) { return; } StyleGroup styleGroup = this.theme.FindStyleGroup(this.Control); if (styleGroup == null) { for (IStylableNode stylableNode = element as IStylableNode; styleGroup == null && stylableNode != null; stylableNode = stylableNode.Parent) { IStylableElement stylableElement = stylableNode as IStylableElement; if (stylableElement != null) { styleGroup = this.theme.FindStyleGroup((IStylableNode)stylableElement); } } } this.SuspendAnimations(); this.ApplyStyleCore(element, styleGroup, (RadObject)this.RootElement, recursive); this.ResumeAnimations(); if (element != this.RootElement) { return; } this.RootElement.IsThemeApplied = true; }
public void Apply(RadObject radObject, bool initializing) { IStylableElement stylable = radObject as IStylableElement; if (stylable != null) { if (!this.ApplySimpleSettings(stylable)) { this.ApplyVisualStateSettings(stylable, initializing); } } else { IStylableNode stylableNode = radObject as IStylableNode; if (stylableNode != null) { foreach (PropertySettingGroup setting in this.settings) { if (setting.Selector == null || setting.Selector.IsCompatible(radObject)) { stylableNode.ApplySettings(setting); } } } } if (!(radObject is RadItem)) { return; } ((RadItem)radObject).ApplyThemeSettingsOverride(); }
public void ApplySettings(IStylableElement element) { List <ThemeSettingOverride> list = new List <ThemeSettingOverride>((IEnumerable <ThemeSettingOverride>) this); ThemeSettingsOverrideCollection.BubbleSort <ThemeSettingOverride>(list, (Comparison <ThemeSettingOverride>)((a, b) => a.StatesCount.CompareTo(b.StatesCount))); foreach (ThemeSettingOverride themeSettingOverride in list) { bool isChildSetting = themeSettingOverride.IsChildSetting; bool flag = themeSettingOverride.IsVisualStateCompatible(element); if (!isChildSetting && flag) { themeSettingOverride.ApplyValue((IStylableNode)element); } else if (isChildSetting && flag) { foreach (IStylableNode stylableNode in element.ChildrenHierarchy) { if (themeSettingOverride.IsChildElementCompatible(stylableNode)) { themeSettingOverride.ApplyValue(stylableNode); } } } } }
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; } } }
protected void SetItemState(RadObject item, params string[] stateNames) { if (item == null) { return; } IStylableElement stylableElement = item as IStylableElement; if (stylableElement == null) { return; } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(stylableElement.ThemeRole); if (stateNames != null && stateNames.Length > 0 && stateNames[0].Length > 0) { if (stringBuilder.Length > 0) { stringBuilder.Append('.'); } stringBuilder.Append(string.Join(ItemStateManagerBase.stateDelimiterString, stateNames)); } stylableElement.VisualState = stringBuilder.ToString(); }
protected override bool CanSelectOverride(RadObject element) { IStylableElement stylableElement = element as IStylableElement; if (stylableElement != null) { return(string.CompareOrdinal(stylableElement.VisualState, this.visualState) == 0); } return(false); }
public virtual string GetInitialState(RadObject item) { IStylableElement stylableElement = item as IStylableElement; if (stylableElement != null) { return(stylableElement.ThemeRole); } return(item.GetType().Name); }
public virtual bool IsCompatible(RadObject element) { IStylableNode stylableNode = element as IStylableNode; if (stylableNode == null) { return(false); } if (this.type == ElementSelectorTypes.VisualStateSelector) { IStylableElement stylableElement = element as IStylableElement; string str = stylableElement != null ? stylableElement.ThemeRole : element.GetType().Name; if (this.value.StartsWith(str)) { return(true); } return(str == this.value); } if (this.type == ElementSelectorTypes.ClassSelector) { if (this.childSelector == null || this.childSelector.Type != ElementSelectorTypes.VisualStateSelector) { return(stylableNode.Class == this.value); } if (this.childSelector.IsCompatible(element)) { for (IStylableNode parent = stylableNode.Parent; parent != null; parent = parent.Parent) { if (parent.Class == this.value) { return(true); } } } return(false); } if (this.type != ElementSelectorTypes.TypeSelector) { return(false); } if (this.childSelector == null || this.childSelector.Type != ElementSelectorTypes.VisualStateSelector || !this.childSelector.IsCompatible(element)) { return(stylableNode.GetThemeEffectiveType().FullName == this.value); } for (IStylableNode parent = stylableNode.Parent; parent != null; parent = parent.Parent) { if (parent.GetThemeEffectiveType().FullName == this.value) { return(true); } } return(false); }
private void ApplyVisualStateSettings(IStylableElement stylable, bool initializing) { RadObject testElement = stylable as RadObject; if (initializing && stylable.VisualState != stylable.ThemeRole) { foreach (PropertySettingGroup setting in this.settings) { if (setting.Selector == null || setting.Selector.Type == ElementSelectorTypes.VisualStateSelector && setting.Selector.IsValid(testElement, stylable.ThemeRole)) { if (setting.Selector.ChildSelector == null) { stylable.ApplySettings(setting); } else if (setting.Selector.ChildSelector.Type != ElementSelectorTypes.VisualStateSelector || setting.Selector.ChildSelector.IsRecursive) { this.ApplyChildVisualStateSelector(stylable, setting); } } } } foreach (string stateFallback in this.GetStateFallbackList(stylable)) { bool flag = false; foreach (PropertySettingGroup setting in this.settings) { if (setting.Selector != null && setting.Selector.Type == ElementSelectorTypes.VisualStateSelector && setting.Selector.IsValid(testElement, stateFallback)) { if (setting.Selector.ChildSelector == null) { stylable.ApplySettings(setting); } else if (setting.Selector.ChildSelector.Type != ElementSelectorTypes.VisualStateSelector) { this.ApplyChildVisualStateSelector(stylable, setting); } flag = true; } } if (flag) { break; } } }
private void attachedElement_RadPropertyChanged(object sender, RadPropertyChangedEventArgs e) { if (this.affectedProperties == null) { return; } IStylableElement stylableElement = sender as IStylableElement; RadObject sender1 = sender as RadObject; if (stylableElement == null) { return; } for (int index = 0; index < this.affectedProperties.Count; ++index) { if (e.Property == this.affectedProperties[index]) { this.eventHandler(sender1, e); break; } } }
public bool IsVisualStateCompatible(IStylableElement stylable) { if (!this.visualState.Contains(".")) { if (this.visualState == string.Empty) { return(stylable.ThemeRole == stylable.VisualState); } return(stylable.VisualState.Contains(this.visualState)); } if (this.states == null) { this.states = this.visualState.Split('.'); } string[] strArray; if (!stylable.VisualState.Contains(".")) { strArray = new string[1] { stylable.VisualState } } ; else { strArray = stylable.VisualState.Split('.'); } string[] array = strArray; foreach (string state in this.states) { if (Array.IndexOf <string>(array, state) < 0) { return(false); } } return(true); }
private void ApplyStyleCore( RadObject element, StyleGroup styleGroup, RadObject stopElement, bool recursive) { IStylableElement stylableElement = element as IStylableElement; IStylableNode stylableNode1 = element as IStylableNode; bool flag1 = stylableElement != null; RadItem radItem = element as RadItem; RadElement radElement = element as RadElement; if (radItem != null) { flag1 = radItem.CanHaveOwnStyle; } else if (radElement != null) { flag1 = !string.IsNullOrEmpty(radElement.Class); } if (flag1) { StyleSheet styleSheet = (StyleSheet)null; RadControl control = this.Control as RadControl; if (control != null) { styleGroup = control.ResolveStyleGroupForElement(styleGroup, element); } if (styleGroup != null) { styleSheet = styleGroup.CreateStyleSheet(element); } if (styleSheet == null) { StyleGroup styleGroup1 = this.theme.FindStyleGroup(stylableNode1); if (styleGroup1 == null) { for (IStylableNode parent = stylableNode1.Parent; parent != null && styleGroup1 == null && parent != stopElement; parent = parent.Parent) { if (parent.Style != null) { bool flag2 = false; foreach (PropertySettingGroup propertySettingGroup in parent.Style.PropertySettingGroups) { if (propertySettingGroup.Selector != null && propertySettingGroup.Selector.Type != ElementSelectorTypes.VisualStateSelector && (propertySettingGroup.Selector.ChildSelector != null && propertySettingGroup.Selector.ChildSelector.Type != ElementSelectorTypes.VisualStateSelector) && (propertySettingGroup.Selector.IsCompatible(parent as RadObject) && propertySettingGroup.Selector.ChildSelector.IsCompatible(element))) { stylableNode1.ApplySettings(propertySettingGroup); flag2 = true; break; } } if (flag2) { break; } } styleGroup1 = this.theme.FindStyleGroup(parent); } } if (styleGroup1 != null) { styleSheet = styleGroup1.CreateStyleSheet(element); styleGroup = styleGroup1; } } if (styleSheet == null && stylableElement != null && stylableElement.FallbackToDefaultTheme) { styleGroup = ThemeRepository.ControlDefault.FindStyleGroup((IStylableNode)stylableElement); if (styleGroup != null) { styleSheet = styleGroup.CreateStyleSheet(element); } } if (radElement != null) { if (radElement.GetValueSource(RadElement.StyleProperty) != ValueSource.Local || radElement.Style == null) { int num = (int)radElement.SetDefaultValueOverride(RadElement.StyleProperty, (object)styleSheet); } } else { stylableNode1.Style = styleSheet; } if (radElement != null) { radElement.styleVersion = this.styleVersion; } } if (!recursive) { return; } IStylableNode stylableNode2 = element as IStylableNode; if (stylableNode2 == null) { return; } if (radElement == null || stylableElement != null && stylableElement.FallbackToDefaultTheme) { stopElement = element; } foreach (RadObject child in stylableNode2.Children) { this.ApplyStyleCore(child, styleGroup, stopElement, recursive); } }
private bool ApplySimpleSettings(IStylableElement stylable) { RadObject testElement = stylable as RadObject; List <PropertySettingGroup> propertySettingGroupList = (List <PropertySettingGroup>)null; foreach (PropertySettingGroup setting in this.settings) { if (setting.Selector == null) { stylable.ApplySettings(setting); } else if (setting.Selector.Type != ElementSelectorTypes.VisualStateSelector) { ElementSelector selector = setting.Selector; if (setting.Selector.IsValid(testElement, string.Empty)) { if (setting.Selector.ChildSelector == null) { stylable.ApplySettings(setting); selector = (ElementSelector)null; } else { selector = setting.Selector.ChildSelector; } } else if (setting.Selector.ChildSelector != null && setting.Selector.ChildSelector.Type == ElementSelectorTypes.VisualStateSelector) { if (propertySettingGroupList == null) { propertySettingGroupList = new List <PropertySettingGroup>(); } propertySettingGroupList.Add(setting); continue; } if (selector != null) { this.ApplySimpleSelectorToChildren((IStylableNode)stylable, setting, selector); } } } if (propertySettingGroupList != null) { foreach (string stateFallback in this.GetStateFallbackList(stylable)) { bool flag = false; foreach (PropertySettingGroup group in propertySettingGroupList) { if (group.Selector.ChildSelector.IsValid(testElement, stateFallback)) { stylable.ApplySettings(group); flag = true; break; } } if (flag) { return(true); } } } return(false); }