diff --git a/ModernWpf/Controls/IconElement.cs b/ModernWpf/Controls/IconElement.cs
index 588fad29..fb33428f 100644
--- a/ModernWpf/Controls/IconElement.cs
+++ b/ModernWpf/Controls/IconElement.cs
@@ -18,6 +18,8 @@ private protected IconElement()
{
}
+ #region Foreground
+
///
/// Identifies the Foreground dependency property.
///
@@ -25,7 +27,20 @@ private protected IconElement()
TextElement.ForegroundProperty.AddOwner(
typeof(IconElement),
new FrameworkPropertyMetadata(SystemColors.ControlTextBrush,
- FrameworkPropertyMetadataOptions.Inherits));
+ FrameworkPropertyMetadataOptions.Inherits,
+ OnForegroundPropertyChanged));
+
+ private static void OnForegroundPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
+ {
+ ((IconElement)sender).OnForegroundPropertyChanged(args);
+ }
+
+ private void OnForegroundPropertyChanged(DependencyPropertyChangedEventArgs args)
+ {
+ var baseValueSource = DependencyPropertyHelper.GetValueSource(this, args.Property).BaseValueSource;
+ _isForegroundDefaultOrInherited = baseValueSource <= BaseValueSource.Inherited;
+ UpdateShouldInheritForegroundFromVisualParent();
+ }
///
/// Gets or sets a brush that describes the foreground color.
@@ -40,6 +55,8 @@ public Brush Foreground
set { SetValue(ForegroundProperty, value); }
}
+ #endregion
+
#region VisualParentForeground
private static readonly DependencyProperty VisualParentForegroundProperty =
@@ -98,6 +115,15 @@ private protected virtual void OnShouldInheritForegroundFromVisualParentChanged(
{
}
+ private void UpdateShouldInheritForegroundFromVisualParent()
+ {
+ ShouldInheritForegroundFromVisualParent =
+ _isForegroundDefaultOrInherited &&
+ Parent != null &&
+ VisualParent != null &&
+ Parent != VisualParent;
+ }
+
private protected UIElementCollection Children
{
get
@@ -141,8 +167,7 @@ protected override Size ArrangeOverride(Size finalSize)
protected override void OnVisualParentChanged(DependencyObject oldParent)
{
base.OnVisualParentChanged(oldParent);
-
- ShouldInheritForegroundFromVisualParent = Parent != null && VisualParent != null && Parent != VisualParent;
+ UpdateShouldInheritForegroundFromVisualParent();
}
private void EnsureLayoutRoot()
@@ -161,6 +186,7 @@ private void EnsureLayoutRoot()
}
private Grid _layoutRoot;
+ private bool _isForegroundDefaultOrInherited = true;
private bool _shouldInheritForegroundFromVisualParent;
}
}