Skip to content
Draft
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
46 changes: 39 additions & 7 deletions source/iNKORE.UI.WPF.Modern/Controls/IconAndText.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
using iNKORE.UI.WPF.Controls;
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace iNKORE.UI.WPF.Modern.Controls
{
public class IconAndText : ContentControl
{
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;
}
}
Comment on lines +10 to +53
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.

public FontIconData? Icon
{
get { return (FontIconData?)GetValue(IconProperty); }
Expand Down Expand Up @@ -50,4 +82,4 @@ public double IconSize

#endregion
}
}
}
Loading