Skip to content
Open
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 @@ -77,26 +77,22 @@ private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyCha
return;
}

if (e.NewValue is not true)
{
expander.Expanded -= OnExpanderExpandedOrCollapsed;
expander.Collapsed -= OnExpanderExpandedOrCollapsed;
return;
}

expander.Expanded += OnExpanderExpandedOrCollapsed;
expander.Collapsed += OnExpanderExpandedOrCollapsed;

if (expander.IsLoaded)
{
InitializeExpanderState(expander);
}
else
{
expander.Loaded += TriggerExpandAnimationOnLoad;
}

void TriggerExpandAnimationOnLoad(object sender, RoutedEventArgs routedEventArgs)
if (e.NewValue is true)
{
if (expander.IsLoaded)
{
InitializeExpanderState(expander);
}
else
{
expander.Loaded += TriggerExpandAnimationOnLoad;
}
}

expander.Expanded += OnExpanderExpandedOrCollapsed;
expander.Collapsed += OnExpanderExpandedOrCollapsed;
Comment on lines +92 to +93
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Event handlers are registered unconditionally regardless of whether IsEnabled is true or false. This means handlers will be attached even when the feature is disabled, and they will be registered multiple times if the property is set repeatedly. This can lead to memory leaks and unexpected behavior. The handlers should only be registered when IsEnabled is true, and should be unregistered when IsEnabled changes to false.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback


void TriggerExpandAnimationOnLoad(object sender, RoutedEventArgs routedEventArgs)
{
InitializeExpanderState(expander);
expander.Loaded -= TriggerExpandAnimationOnLoad;
Expand All @@ -105,13 +101,19 @@ void TriggerExpandAnimationOnLoad(object sender, RoutedEventArgs routedEventArgs

private static void OnExpanderExpandedOrCollapsed(object sender, RoutedEventArgs e)
{
if (sender is not Expander expander)
if (sender is not Expander expander || !expander.IsLoaded)
{
return;
}

RunExpanderAnimation(expander);
}
if (GetIsEnabled(expander))
RunExpanderAnimation(expander);
else
{
var toAnimateControl = GetToAnimateControl(expander);
toAnimateControl?.Visibility = expander.IsExpanded ? Visibility.Visible : Visibility.Collapsed;
}
}

#endregion

Expand Down Expand Up @@ -176,6 +178,7 @@ private static void AnimateExpand(Expander expander)
{
var toAnimateControl = GetToAnimateControl(expander);
toAnimateControl.BeginAnimation(UIElement.VisibilityProperty, null);
toAnimateControl.Visibility = Visibility.Visible;
UpdateLayout(toAnimateControl);

if (toAnimateControl.RenderTransform is not TranslateTransform translateTransform)
Expand Down
Loading