/// <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> /// 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> /// Applies a style to the element. /// </summary> /// <param name="style">The style which is being applied.</param> /// <param name="selector">The selector which caused the style to be applied.</param> /// <param name="navigationExpression">The navigation expression associated with the style.</param> /// <param name="dprop">A <see cref="DependencyProperty"/> that identifies the dependency property which is being styled.</param> protected internal virtual void ApplyStyle(UvssRule style, UvssSelector selector, NavigationExpression?navigationExpression, DependencyProperty dprop) { if (dprop != null) { dprop.ApplyStyle(this, style); } }
/// <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> public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, Trigger trigger) { Contract.Require(uv, "uv"); var key = new StyleKey(trigger.CanonicalName, navigationExpression); var priority = CalculatePriorityFromSelector(selector, false); PrioritizedTrigger existing; if (!triggers.TryGetValue(key, out existing) || selector.IsHigherPriorityThan(existing.Selector)) { triggers[key] = new PrioritizedTrigger(trigger, selector, priority); } }
/// <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> /// Adds a style 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="style">The style to add to the prioritizer.</param> public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssStyle style) { Contract.Require(uv, "uv"); var key = new StyleKey(style.CanonicalName, navigationExpression); var priority = CalculatePriorityFromSelector(selector, style.IsImportant); PrioritizedStyle existing; if (!styles.TryGetValue(key, out existing)) { styles[key] = new PrioritizedStyle(style, selector, priority); } else { if (selector.IsHigherPriorityThan(existing.Selector) && (style.IsImportant || !existing.Style.IsImportant)) { styles[key] = new PrioritizedStyle(style, selector, priority); } } }
/// <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="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> public PrioritizedStyle(UvssStyle style, UvssSelector selector, Int32 priority) { this.Style = style; this.Selector = selector; this.Priority = priority; }
/// <summary> /// Initializes a new instance of the <see cref="UvssStoryboardTarget"/> class. /// </summary> /// <param name="selector">The target's selector.</param> /// <param name="filter">The storyboard target's type filter.</param> /// <param name="animations">The target's collection of animations.</param> internal UvssStoryboardTarget(UvssSelector selector, UvssStoryboardTargetFilter filter, UvssStoryboardAnimationCollection animations) { this.selector = selector; this.filter = filter; this.animations = animations; }
/// <summary> /// Initializes a new instance of the <see cref="StoryboardTarget"/> class. /// </summary> /// <param name="selector">The selector which specifies which elements this target applies to.</param> public StoryboardTarget(UvssSelector selector) { this.selector = selector; this.animations = new StoryboardTargetAnimationCollection(this); }
/// <inheritdoc/> protected internal sealed override void ApplyStyle(UvssStyle style, UvssSelector selector, NavigationExpression? navigationExpression, DependencyProperty dp) { base.ApplyStyle(style, selector, navigationExpression, dp); }
/// <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> public PrioritizedTrigger(Trigger trigger, UvssSelector selector, Int32 priority) { this.Trigger = trigger; this.Selector = selector; this.Priority = priority; }
/// <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> /// 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); }
/// <inheritdoc/> protected internal sealed override void ApplyStyle(UvssRule style, UvssSelector selector, NavigationExpression?navigationExpression, DependencyProperty dp) { base.ApplyStyle(style, selector, navigationExpression, dp); }
/// <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); }