예제 #1
0
        /// <inheritdoc/>
        public override string ToString()
        {
            if (_selectorString == null)
            {
                var builder = new StringBuilder();

                if (_previous != null)
                {
                    builder.Append(_previous.ToString());
                }

                builder.Append('[');

                if (_property.IsAttached)
                {
                    builder.Append(_property.OwnerType.Name);
                    builder.Append('.');
                }

                builder.Append(_property.Name);
                builder.Append('=');
                builder.Append(_value);
                builder.Append(']');

                _selectorString = builder.ToString();
            }

            return(_selectorString);
        }
예제 #2
0
        /// <summary>
        /// Attaches the style to a control if the style's selector matches.
        /// </summary>
        /// <param name="control">The control to attach to.</param>
        /// <param name="container">
        /// The control that contains this style. May be null.
        /// </param>
        public void Attach(IStyleable control, IStyleHost container)
        {
            if (Selector != null)
            {
                var description = "Style " + Selector.ToString();
                var match       = Selector.Match(control);

                if (match.ImmediateResult != false)
                {
                    var activator = (match.ObservableResult ?? True)
                                    .TakeUntil(control.StyleDetach);

                    foreach (var setter in Setters)
                    {
                        setter.Apply(this, control, activator);
                    }
                }
            }
            else if (control == container)
            {
                foreach (var setter in Setters)
                {
                    setter.Apply(this, control, null);
                }
            }
        }
예제 #3
0
파일: Style.cs 프로젝트: vebin/Perspex
        /// <summary>
        /// Attaches the style to a control if the style's selector matches.
        /// </summary>
        /// <param name="control">The control to attach to.</param>
        /// <param name="container">
        /// The control that contains this style. May be null.
        /// </param>
        public void Attach(IStyleable control, IStyleHost container)
        {
            if (Selector != null)
            {
                var description = "Style " + Selector.ToString();
                var match       = Selector.Match(control);

                if (match.ImmediateResult != false)
                {
                    var subs = GetSubscriptions(control);

                    foreach (var setter in Setters)
                    {
                        var sub = setter.Apply(this, control, match.ObservableResult);
                        subs.Add(sub);
                    }
                }
            }
            else if (control == container)
            {
                var subs = GetSubscriptions(control);

                foreach (var setter in Setters)
                {
                    var sub = setter.Apply(this, control, null);
                    subs.Add(sub);
                }
            }
        }
예제 #4
0
        public override string ToString()
        {
            if (_selectorString == null)
            {
                _selectorString = _parent.ToString() + " /template/ ";
            }

            return(_selectorString);
        }
예제 #5
0
 /// <summary>
 /// Returns a string representation of the style.
 /// </summary>
 /// <returns>A string representation of the style.</returns>
 public override string ToString()
 {
     if (Selector != null)
     {
         return("Style: " + Selector.ToString());
     }
     else
     {
         return("Style");
     }
 }
예제 #6
0
        /// <summary>
        /// Attaches the style to a control if the style's selector matches.
        /// </summary>
        /// <param name="control">The control to attach to.</param>
        public void Attach(IStyleable control)
        {
            var description = "Style " + Selector.ToString();
            var match       = Selector.Match(control);

            if (match.ImmediateResult != false)
            {
                foreach (var setter in Setters)
                {
                    setter.Apply(this, control, match.ObservableResult);
                }
            }
        }
예제 #7
0
        private string BuildSelectorString()
        {
            var builder = new StringBuilder();

            if (_previous != null)
            {
                builder.Append(_previous.ToString());
            }

            if (TargetType != null)
            {
                if (IsConcreteType)
                {
                    builder.Append(TargetType.Name);
                }
                else
                {
                    builder.Append(":is(");
                    builder.Append(TargetType.Name);
                    builder.Append(")");
                }
            }

            if (Name != null)
            {
                builder.Append('#');
                builder.Append(Name);
            }

            if (_classes.IsValueCreated && _classes.Value.Count > 0)
            {
                foreach (var c in Classes)
                {
                    if (!c.StartsWith(":"))
                    {
                        builder.Append('.');
                    }

                    builder.Append(c);
                }
            }

            return(builder.ToString());
        }
예제 #8
0
        public void PesudoClass_Selector_Should_Have_Correct_String_Representation()
        {
            var target = new Selector().Class(":foo");

            Assert.Equal(":foo", target.ToString());
        }
예제 #9
0
 /// <summary>
 /// Returns a string representation of the style.
 /// </summary>
 /// <returns>A string representation of the style.</returns>
 public override string ToString()
 {
     return("Style: " + Selector.ToString());
 }