/// <summary> /// Initializes a new instance of the <see cref="PrioritizedStyle"/> structure. /// </summary> /// <param name="style">The style being applied.</param> /// <param name="selector">The selector which caused the style to be applied.</param> /// <param name="priority">The style's priority.</param> /// <param name="index">The index of the style's rule set within its style sheet.</param> public PrioritizedStyle(UvssRule style, UvssSelector selector, Int32 priority, Int32 index) { this.Style = style; this.Selector = selector; this.Priority = priority; this.Index = index; }
/// <summary> /// Adds a trigger to the prioritizer. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="selector">The selector which caused this style to be considered.</param> /// <param name="navigationExpression">The navigation expression associated with the style.</param> /// <param name="trigger">The trigger to add to the prioritizer.</param> /// <param name="index">The index of the trigger's rule set within the style sheet.</param> public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression?navigationExpression, UvssTrigger trigger, Int32 index) { Contract.Require(uv, nameof(uv)); var key = new StyleKey(trigger.CanonicalName, navigationExpression); var priority = CalculatePriorityFromSelector(selector, false); PrioritizedTrigger existing; if (!triggers.TryGetValue(key, out existing)) { triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index); } else { var comparison = selector.ComparePriority(existing.Selector); if (comparison == 0 && index > existing.Index) { comparison = 1; } if (comparison > 0 && (trigger.IsImportant || !existing.Trigger.IsImportant)) { triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index); } } }
/// <summary> /// Initializes a new instance of the <see cref="PrioritizedTrigger"/> structure. /// </summary> /// <param name="trigger">The trigger being applied.</param> /// <param name="selector">The selector which caused the trigger to be applied.</param> /// <param name="priority">The trigger's priority.</param> /// <param name="index">The index of the trigger's rule set within its style sheet.</param> public PrioritizedTrigger(UvssTrigger trigger, UvssSelector selector, Int32 priority, Int32 index) { this.Trigger = trigger; this.Selector = selector; this.Priority = priority; this.Index = index; }
/// <summary> /// Gets a value indicating whether the rule set matches the specified UI element. /// </summary> /// <param name="element">The UI element to evaluate.</param> /// <param name="selector">The selector that matches the element, if any.</param> /// <returns><see langword="true"/> if the rule set matches the specified UI element; otherwise, <see langword="false"/>.</returns> public Boolean MatchesElement(UIElement element, out UvssSelector selector) { selector = null; foreach (var potentialMatch in selectors) { if (potentialMatch.MatchesElement(element)) { if (selector == null || potentialMatch.ComparePriority(selector) >= 0) { selector = potentialMatch; } } } return(selector != null); }
/// <summary> /// Compares the priority of this selector with the priority of another selector /// and returns a value which represents their relative order. /// </summary> /// <param name="selector">The selector to compare to this selector.</param> /// <returns>A value which represents the relative order of the objects being compared.</returns> public Int32 ComparePriority(UvssSelector selector) { Contract.Require(selector, nameof(selector)); if (IsDirectlyTargeted && !selector.IsDirectlyTargeted) { return(1); } if (!IsDirectlyTargeted && selector.IsDirectlyTargeted) { return(-1); } return(priority.CompareTo(selector.priority)); }
/// <summary> /// Adds the specified rule set to the style prioritizer. /// </summary> private void AddRuleSetToPrioritizer(UIElement element, UvssSelector selector, UvssRuleSet ruleSet, Int32 index) { if (!selector.MatchesElement(element)) { return; } var navexp = NavigationExpression.FromUvssNavigationExpression(Ultraviolet, selector.NavigationExpression); foreach (var rule in ruleSet.Rules) { prioritizer.Add(Ultraviolet, selector, navexp, rule, index); } foreach (var trigger in ruleSet.Triggers) { prioritizer.Add(Ultraviolet, selector, navexp, trigger, index); } }
/// <summary> /// Calculates the specified selector's relative priority. /// </summary> /// <param name="selector">The selector to evaluate.</param> /// <param name="important">A value indicating whether the style should be considered important.</param> /// <returns>The relative priority of the specified selector.</returns> private Int32 CalculatePriorityFromSelector(UvssSelector selector, Boolean important) { const Int32 ImportantStylePriority = 1000000000; return(selector.Priority + (important ? ImportantStylePriority : 0)); }
/// <summary> /// Initializes a new instance of thhe <see cref="CategorizedRuleSet"/> structure. /// </summary> /// <param name="selector">The selector which applies the categorized rule set.</param> /// <param name="ruleSet">The rule set which has been categorized.</param> /// <param name="index">The index of the rule set within the style sheet.</param> public CategorizedRuleSet(UvssSelector selector, UvssRuleSet ruleSet, Int32 index) { this.Selector = selector; this.RuleSet = ruleSet; this.Index = index; }
/// <summary> /// Initializes a new instance of the <see cref="PlayStoryboardTriggerAction"/> class. /// </summary> /// <param name="storyboardName">The name of the storyboard to play.</param> /// <param name="selector">A selector specifying which elements will be targeted by the storyboard.</param> internal PlayStoryboardTriggerAction(String storyboardName, UvssSelector selector) { this.storyboardName = storyboardName; this.selector = selector; }
/// <summary> /// Initializes a new instance of the <see cref="SetTriggerAction"/> class. /// </summary> /// <param name="selector">A UVSS selector which specifies the target (or targets) of the action.</param> /// <param name="propertyName">The styling name of the dependency property which is set by this action.</param> /// <param name="propertyValue">The value to which the action sets its associated dependency property.</param> internal SetTriggerAction(UvssSelector selector, DependencyName propertyName, DependencyValue propertyValue) { this.selector = selector; this.propertyName = propertyName; this.propertyValue = propertyValue; }