/// <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> /// Applies the specified style to the dependency property. /// </summary> /// <param name="dobj">The dependency object on which to set the style.</param> /// <param name="style">The style to set on this dependency property.</param> /// <param name="provider">An object that supplies culture-specific formatting information.</param> internal void ApplyStyle(DependencyObject dobj, UvssStyle style, IFormatProvider provider) { if (styleSetter == null) throw new InvalidOperationException(PresentationStrings.DependencyPropertyIsReadOnly.Format(Name)); styleSetter(dobj, style, provider); }
/// <summary> /// Applies the specified style to the dependency property. /// </summary> /// <param name="dobj">The dependency object on which to set the style.</param> /// <param name="style">The style to set on this dependency property.</param> internal void ApplyStyle(DependencyObject dobj, UvssStyle style) { if (styleSetter == null) throw new InvalidOperationException(PresentationStrings.DependencyPropertyIsReadOnly.Format(Name)); styleSetter(dobj, style, CultureInfo.InvariantCulture); }
/// <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; }
/// <inheritdoc/> protected internal sealed override void ApplyStyle(UvssStyle style, UvssSelector selector, NavigationExpression? navigationExpression, DependencyProperty dp) { base.ApplyStyle(style, selector, navigationExpression, dp); }
/// <summary> /// Consumes a sequence of tokens representing a UVSS style or UVSS trigger. /// </summary> /// <param name="state">The parser state.</param> /// <param name="styles">The list containing the styles being created.</param> /// <param name="triggers">The list containing the triggers being created.</param> /// <returns><c>true</c> if a style or trigger was successfully consumed; otherwise, <c>false</c>.</returns> private static Boolean ConsumeStyleOrTrigger(UvssParserState state, List<UvssStyle> styles, List<Trigger> triggers) { state.AdvanceBeyondWhiteSpace(); if (state.IsPastEndOfStream) return false; var qualifierImportant = false; var nameToken = state.TryConsumeNonWhiteSpace(); if (nameToken.HasValue && nameToken.Value.TokenType == UvssLexerTokenType.TriggerKeyword) { return ConsumeTrigger(state, triggers); } MatchTokenOrFail(state, nameToken, UvssLexerTokenType.StyleName); AdvanceBeyondWhiteSpaceOrFail(state); UvssStyleArgumentsCollection arguments; if (state.CurrentToken.TokenType == UvssLexerTokenType.OpenParenthesis) { arguments = ConsumeStyleArguments(state); ValidateStyleArguments(state, nameToken.Value.Value, arguments); } else { arguments = new UvssStyleArgumentsCollection(null); } var colonToken = state.TryConsumeNonWhiteSpace(); MatchTokenOrFail(state, colonToken, UvssLexerTokenType.Colon); var valueTokens = new List<UvssLexerToken>(); while (!state.IsPastEndOfStream) { var token = state.Consume(); if (token.TokenType == UvssLexerTokenType.Semicolon) { break; } if (token.TokenType == UvssLexerTokenType.StyleQualifier) { if (String.Equals("!important", token.Value, StringComparison.OrdinalIgnoreCase)) { qualifierImportant = true; } continue; } valueTokens.Add(token); } var container = default(String); var name = nameToken.Value.Value; var value = String.Join(String.Empty, valueTokens.Select(x => x.Value)).Trim(); if (name.Contains('.')) { var nameParts = name.Split('.'); container = nameParts[0]; name = nameParts[1]; } var style = new UvssStyle(arguments, container, name, value, qualifierImportant); styles.Add(style); return true; }
/// <inheritdoc/> internal override void ApplyStyledVisualStateTransition(UvssStyle style) { Contract.Require(style, "style"); if (View != null && View.StyleSheet != null) { var value = (style.CachedResolvedValue != null && style.CachedResolvedValue is String) ? (String)style.CachedResolvedValue : style.Value.Trim(); style.CachedResolvedValue = value; var storyboard = View.StyleSheet.InstantiateStoryboardByName(Ultraviolet, value); if (storyboard != null) { var group = default(String); var from = default(String); var to = default(String); switch (style.Arguments.Count) { case 2: group = style.Arguments[0]; from = null; to = style.Arguments[1]; break; case 3: group = style.Arguments[0]; from = style.Arguments[1]; to = style.Arguments[2]; break; default: throw new NotSupportedException(); } VisualStateGroups.SetVisualStateTransition(group, from, to, storyboard); } } }