Skip to content
Open
Show file tree
Hide file tree
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
74 changes: 47 additions & 27 deletions source/iNKORE.UI.WPF.Modern/Controls/FontIcon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using iNKORE.UI.WPF.Modern.Common;
using iNKORE.UI.WPF.Modern.Common;
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using System.ComponentModel;
using System.Windows;
Expand Down Expand Up @@ -235,37 +235,57 @@ private protected override void InitializeChildren()
FontWeight = FontWeight,
Text = Glyph
};

if (ShouldInheritForegroundFromVisualParent)
// Instead of manually copying brushes, just bind. WPF inheritance will supply parent Foreground
// when our own Foreground is default; explicit user-set Foreground flows through.
_textBlock.SetBinding(TextBlock.ForegroundProperty, new System.Windows.Data.Binding
{
_textBlock.Foreground = VisualParentForeground;
}
Path = new PropertyPath(nameof(Foreground)),
Source = this
});

Children.Add(_textBlock);
}

private protected override void OnShouldInheritForegroundFromVisualParentChanged()
{
if (_textBlock != null)
{
if (ShouldInheritForegroundFromVisualParent)
{
_textBlock.Foreground = VisualParentForeground;
}
else
{
_textBlock.ClearValue(TextBlock.ForegroundProperty);
}
}
}

private protected override void OnVisualParentForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
{
if (ShouldInheritForegroundFromVisualParent && _textBlock != null)
{
_textBlock.Foreground = (Brush)args.NewValue;
}
}
// Foreground propagation now handled purely via binding; overrides no longer necessary.
// Legacy foreground inheritance logic (kept for reference only):
//
// private protected override void OnShouldInheritForegroundFromVisualParentChanged()
// {
// if (_textBlock != null)
// {
// if (ShouldInheritForegroundFromVisualParent)
// {
// _textBlock.Foreground = VisualParentForeground;
// }
// else
// {
// _textBlock.ClearValue(TextBlock.ForegroundProperty);
// // Apply our own Foreground if explicitly set.
// if (Foreground != null)
// {
// _textBlock.Foreground = Foreground;
// }
// }
// }
// }
//
// private protected override void OnVisualParentForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
// {
// if (ShouldInheritForegroundFromVisualParent && _textBlock != null)
// {
// _textBlock.Foreground = (Brush)args.NewValue;
// }
// }
//
// private protected override void OnOwnForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
// {
// if (!ShouldInheritForegroundFromVisualParent && _textBlock != null)
// {
// // When we're not inheriting from visual parent, push our Foreground to the text block.
// _textBlock.Foreground = (Brush)args.NewValue;
// }
// }
//

private TextBlock _textBlock;

Expand Down
29 changes: 25 additions & 4 deletions source/iNKORE.UI.WPF.Modern/Controls/IconElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using iNKORE.UI.WPF.Modern.Common;
using iNKORE.UI.WPF.Modern.Common;
using System;
using System.ComponentModel;
using System.Windows;
Expand Down Expand Up @@ -41,6 +41,8 @@ private void OnForegroundPropertyChanged(DependencyPropertyChangedEventArgs args
var baseValueSource = DependencyPropertyHelper.GetValueSource(this, args.Property).BaseValueSource;
_isForegroundDefaultOrInherited = baseValueSource <= BaseValueSource.Inherited;
UpdateShouldInheritForegroundFromVisualParent();
// Notify derived classes so they can push Foreground to internal visuals when not inheriting.
OnOwnForegroundPropertyChanged(args);
}

/// <summary>
Expand Down Expand Up @@ -116,11 +118,30 @@ private protected virtual void OnShouldInheritForegroundFromVisualParentChanged(

private void UpdateShouldInheritForegroundFromVisualParent()
{
// Legacy logic (before simplification) kept for reference:
// We originally required that the element had both a logical Parent and a VisualParent and that they differed.
// This proved too restrictive in scenarios where the logical and visual tree relationships caused FontIcon
// to miss theme brush updates (e.g., in the iconography gallery) leaving glyphs with a stale/dark brush.
//
// ShouldInheritForegroundFromVisualParent =
// _isForegroundDefaultOrInherited &&
// Parent != null &&
// VisualParent != null &&
// Parent != VisualParent;

// if our Foreground is default/inherited and we have a visual parent, bind to it.
ShouldInheritForegroundFromVisualParent =
_isForegroundDefaultOrInherited &&
Parent != null &&
VisualParent != null &&
Parent != VisualParent;
VisualParent != null; // Always inherit from visual parent when our Foreground is default/inherited.
}

/// <summary>
/// Called whenever this element's own Foreground property changes (after inheritance logic updated).
/// Allows derived classes to propagate the Foreground to visual children when not inheriting directly from visual parent.
/// </summary>
/// <param name="args">Change args.</param>
private protected virtual void OnOwnForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
{
}

private protected UIElementCollection Children
Expand Down
Loading