/// <inheritdoc/> public void Attach(IStyleable control, IStyleHost container) { if (Source != null) { Loaded.Attach(control, container); } }
/// <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); } } }
/// <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); } }
/// <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); } } }
/// <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); } } }
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) { _styleRoot = null; base.OnDetachedFromLogicalTree(e); foreach (var l in _layers) { ((ILogical)l).NotifyDetachedFromLogicalTree(e); } }
/// <inheritdoc/> public bool Attach(IStyleable control, IStyleHost container) { if (Source != null) { return(Loaded.Attach(control, container)); } return(false); }
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { base.OnAttachedToLogicalTree(e); _styleRoot = e.Root; foreach (var l in _layers) { ((ILogical)l).NotifyAttachedToLogicalTree(e); } }
public AvaloniaStyleManager(IStyleHost window) { _window = window; if (window.Styles.Count == 0) { window.Styles.Add(_seaStyle); } else { window.Styles[0] = _seaStyle; } }
/// <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); } }
/// <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); }
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); }
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); } }
public static ILogicalRoot FindLogicalRoot(this IStyleHost styleHost) { while (styleHost != null) { if (styleHost is ILogicalRoot logicalRoot) { return(logicalRoot); } styleHost = styleHost.StylingParent; } return(null); }
/// <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); }
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); } }
/// <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); }
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); }
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; }
private IStyleHost GetParentContainer(IStyleHost container) { return(container.GetVisualAncestors().OfType <IStyleHost>().FirstOrDefault()); }
/// <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; }
public SelectorMatchResult TryAttach(IStyleable target, IStyleHost host) => Loaded.TryAttach(target, host);
private IStyleHost GetParentContainer(IStyleHost container) { return container.GetVisualAncestors().OfType<IStyleHost>().FirstOrDefault(); }