Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ internal static class AspidThemeStyleSheetExtensions
/// Adds <see cref="AspidStyles.DefaultStyleSheet"/> to the element and, when the user has
/// configured one, layers <see cref="AspidThemeSettings.OverrideStyleSheet"/> on top of it.
/// The override is added to the same element as the base palette so its <c>:root</c> tokens
/// take precedence. The element re-applies the override live whenever
/// <see cref="AspidThemeSettings.Changed"/> fires and unsubscribes when it leaves the panel.
/// take precedence. The element subscribes to <see cref="AspidThemeSettings.Changed"/> while
/// attached to a panel (re-applying the current override on attach) and unsubscribes when it
/// leaves the panel, so live updates survive detach/reattach and never leak when never attached.
/// </summary>
/// <param name="element">The element that receives the theme style sheets.</param>
/// <returns>The element, for chaining.</returns>
Expand All @@ -34,7 +35,11 @@ void OnThemeChanged()
if (applied != null) element.AddStyleSheets(applied);
}

AspidThemeSettings.Changed += OnThemeChanged;
element.RegisterCallback<AttachToPanelEvent>(_ =>
{
OnThemeChanged();
AspidThemeSettings.Changed += OnThemeChanged;
});
element.RegisterCallback<DetachFromPanelEvent>(_ => AspidThemeSettings.Changed -= OnThemeChanged);

return element;
Expand Down
Loading