Exemplo n.º 1
0
 /// <inheritdoc/>
 public void Attach(IStyleable control, IStyleHost container)
 {
     if (Source != null)
     {
         Loaded.Attach(control, container);
     }
 }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 3
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)
 {
     foreach (IStyle style in this)
     {
         style.Attach(control, container);
     }
 }
Exemplo n.º 4
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 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);
                }
            }
        }
Exemplo n.º 5
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 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);
                }
            }
        }
Exemplo n.º 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>
        /// <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);
                }
            }
        }
Exemplo n.º 7
0
 /// <inheritdoc/>
 public void Attach(IStyleable control, IStyleHost container)
 {
     if (Source != null)
     {
         Loaded.Attach(control, container);
     }
 }
Exemplo n.º 8
0
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     _styleRoot = null;
     base.OnDetachedFromLogicalTree(e);
     foreach (var l in _layers)
     {
         ((ILogical)l).NotifyDetachedFromLogicalTree(e);
     }
 }
Exemplo n.º 9
0
        /// <inheritdoc/>
        public bool Attach(IStyleable control, IStyleHost container)
        {
            if (Source != null)
            {
                return(Loaded.Attach(control, container));
            }

            return(false);
        }
Exemplo n.º 10
0
        protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
        {
            base.OnAttachedToLogicalTree(e);
            _styleRoot = e.Root;

            foreach (var l in _layers)
            {
                ((ILogical)l).NotifyAttachedToLogicalTree(e);
            }
        }
Exemplo n.º 11
0
 public AvaloniaStyleManager(IStyleHost window)
 {
     _window = window;
     if (window.Styles.Count == 0)
     {
         window.Styles.Add(_seaStyle);
     }
     else
     {
         window.Styles[0] = _seaStyle;
     }
 }
Exemplo n.º 12
0
        /// <inheritdoc/>
        public void Attach(IStyleable control, IStyleHost container)
        {
            if (Source != null)
            {
                if (Loaded == null)
                {
                    var loader = new PerspexXamlLoader();
                    Loaded = (IStyle)loader.Load(Source);
                }

                Loaded.Attach(control, container);
            }
        }
Exemplo n.º 13
0
        /// <inheritdoc/>
        public void Attach(IStyleable control, IStyleHost container)
        {
            if (Source != null)
            {
                if (Loaded == null)
                {
                    var loader = new PerspexXamlLoader();
                    Loaded = (IStyle)loader.Load(Source);
                }

                Loaded.Attach(control, container);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Applies the given style(s) to the given control.
        /// </summary>
        /// <param name="control">The control to apply the style(s) to.</param>
        /// <param name="styleHost">The style set to apply.</param>
        private void ApplyStyles(IStyleable control, IStyleHost styleHost)
        {
            Contract.Requires <ArgumentNullException>(control != null);
            Contract.Requires <ArgumentNullException>(styleHost != null);

            var parentContainer = styleHost.StylingParent;

            if (parentContainer != null)
            {
                ApplyStyles(control, parentContainer);
            }

            styleHost.Styles.Attach(control, styleHost);
        }
Exemplo n.º 15
0
        private void ApplyStyles(IStyleable control, IStyleHost styleHost)
        {
            Contract.Requires<ArgumentNullException>(control != null);
            Contract.Requires<ArgumentNullException>(styleHost != null);

            var parentContainer = styleHost.StylingParent;

            if (parentContainer != null)
            {
                ApplyStyles(control, parentContainer);
            }

            styleHost.Styles.Attach(control, styleHost);
        }
Exemplo n.º 16
0
        private void ApplyStyles(IStyleable target, IStyleHost host)
        {
            var parent = host.StylingParent;

            if (parent != null)
            {
                ApplyStyles(target, parent);
            }

            if (host.IsStylesInitialized)
            {
                host.Styles.TryAttach(target, host);
            }
        }
Exemplo n.º 17
0
        public static ILogicalRoot FindLogicalRoot(this IStyleHost styleHost)
        {
            while (styleHost != null)
            {
                if (styleHost is ILogicalRoot logicalRoot)
                {
                    return(logicalRoot);
                }

                styleHost = styleHost.StylingParent;
            }

            return(null);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Finds the style root element.
        /// </summary>
        /// <param name="e">The style host.</param>
        /// <returns>The style root, null otherwise.</returns>
        private static IStyleRoot FindStyleRoot(IStyleHost e)
        {
            while (e != null)
            {
                var root = e as IStyleRoot;

                if (root != null && root.StylingParent == null)
                {
                    return(root);
                }

                e = e.StylingParent;
            }

            return(null);
        }
Exemplo n.º 19
0
        public void ApplyStyles(IStyleable control)
        {
            IVisual    visual         = control as IVisual;
            IStyleHost styleContainer = visual
                                        .GetSelfAndVisualAncestors()
                                        .OfType <IStyleHost>()
                                        .FirstOrDefault();
            IGlobalStyles global = PerspexLocator.Current.GetService <IGlobalStyles>();

            if (global != null)
            {
                global.Styles.Attach(control, null);
            }

            if (styleContainer != null)
            {
                ApplyStyles(control, styleContainer);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Tries to find a named style resource.
        /// </summary>
        /// <param name="control">The control from which to find the resource.</param>
        /// <param name="name">The resource name.</param>
        /// <returns>
        /// The resource if found, otherwise <see cref="PerspexProperty.UnsetValue"/>.
        /// </returns>
        public static object FindStyleResource(this IStyleHost control, string name)
        {
            Contract.Requires <ArgumentNullException>(control != null);
            Contract.Requires <ArgumentNullException>(name != null);
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(name));

            while (control != null)
            {
                var result = control.Styles.FindResource(name);

                if (result != PerspexProperty.UnsetValue)
                {
                    return(result);
                }

                control = control.StylingParent;
            }

            return(PerspexProperty.UnsetValue);
        }
Exemplo n.º 21
0
        private void ApplyStyles(IStyleable control, IStyleHost container)
        {
            Contract.Requires<ArgumentNullException>(control != null);
            Contract.Requires<ArgumentNullException>(container != null);

            IVisual visual = container as IVisual;

            if (visual != null)
            {
                IStyleHost parentContainer = visual
                    .GetVisualAncestors()
                    .OfType<IStyleHost>()
                    .FirstOrDefault();

                if (parentContainer != null)
                {
                    ApplyStyles(control, parentContainer);
                }
            }

            container.Styles.Attach(control, container);
        }
Exemplo n.º 22
0
        private void ApplyStyles(IStyleable control, IStyleHost container)
        {
            Contract.Requires <ArgumentNullException>(control != null);
            Contract.Requires <ArgumentNullException>(container != null);

            IVisual visual = container as IVisual;

            if (visual != null)
            {
                IStyleHost parentContainer = visual
                                             .GetVisualAncestors()
                                             .OfType <IStyleHost>()
                                             .FirstOrDefault();

                if (parentContainer != null)
                {
                    ApplyStyles(control, parentContainer);
                }
            }

            container.Styles.Attach(control, container);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicalTreeAttachmentEventArgs"/> class.
        /// </summary>
        /// <param name="root">The root of the logical tree.</param>
        public LogicalTreeAttachmentEventArgs(IStyleHost root)
        {
            Contract.Requires<ArgumentNullException>(root != null);

            Root = root;
        }
Exemplo n.º 24
0
 private IStyleHost GetParentContainer(IStyleHost container)
 {
     return(container.GetVisualAncestors().OfType <IStyleHost>().FirstOrDefault());
 }
Exemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicalTreeAttachmentEventArgs"/> class.
        /// </summary>
        /// <param name="root">The root of the logical tree.</param>
        public LogicalTreeAttachmentEventArgs(IStyleHost root)
        {
            Contract.Requires <ArgumentNullException>(root != null);

            Root = root;
        }
Exemplo n.º 26
0
 public SelectorMatchResult TryAttach(IStyleable target, IStyleHost host) => Loaded.TryAttach(target, host);
Exemplo n.º 27
0
 private IStyleHost GetParentContainer(IStyleHost container)
 {
     return container.GetVisualAncestors().OfType<IStyleHost>().FirstOrDefault();
 }