Skip to content

Conversation

@LxHTT
Copy link

@LxHTT LxHTT commented Jan 17, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 17, 2026 13:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where the IconAndText control's icon doesn't update when the Icon property value changes. The root cause was using AddOwner to share FontIcon's IconProperty, which prevented proper change notifications on IconAndText.

Changes:

  • Changed IconProperty from using AddOwner to Register to create an independent property with proper change tracking
  • Added manual icon update logic through OnApplyTemplate override and property change callbacks
  • Removed unused namespace imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +53
private FontIcon _fontIcon;

static IconAndText()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(IconAndText), new FrameworkPropertyMetadata(typeof(IconAndText)));
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();

_fontIcon = GetTemplateChild("Icon") as FontIcon;
UpdateIconElement();
}

#region Properties

public static readonly DependencyProperty IconProperty = FontIcon.IconProperty.AddOwner(typeof(IconAndText));
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(
nameof(Icon),
typeof(FontIconData?),
typeof(IconAndText),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure,
OnIconChanged
)
);

private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is IconAndText iconAndText)
{
iconAndText.UpdateIconElement();
}
}

private void UpdateIconElement()
{
if (_fontIcon != null)
{
_fontIcon.Icon = Icon;
}
}
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual icon update mechanism (OnApplyTemplate, OnIconChanged callback, and UpdateIconElement) appears redundant with the existing TemplateBinding in IconAndText.xaml line 20. With the properly registered DependencyProperty using FrameworkPropertyMetadata, the TemplateBinding should automatically propagate Icon property changes to the FontIcon element. The manual update code adds complexity and could potentially conflict with the binding system. Consider testing whether the fix works with only the property registration change (removing OnApplyTemplate override, OnIconChanged callback, UpdateIconElement method, and _fontIcon field) to rely solely on TemplateBinding as is the standard WPF pattern.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant