Skip to content

Commit 26f69f2

Browse files
authored
Merge pull request #422 from mou-haz/ExpanderInPopupBug
[BUG] Fix Expander in Popup bug
2 parents d71cbc3 + 09a4da7 commit 26f69f2

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

source/iNKORE.UI.WPF.Modern/Controls/Helpers/ExpanderAnimationsHelper.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.ComponentModel;
32
using System.Windows.Controls;
43
using System.Windows;
54
using System.Windows.Media;
@@ -17,11 +16,13 @@ public static string GetToAnimateControlName(Expander element) =>
1716
public static void SetToAnimateControlName(Expander element, string value) =>
1817
element.SetValue(ToAnimateControlNameProperty, value);
1918

19+
private const string DefaultAnimationTargetPartName = "ExpanderContent";
20+
2021
public static readonly DependencyProperty ToAnimateControlNameProperty = DependencyProperty.RegisterAttached(
2122
"ToAnimateControlName",
2223
typeof(string),
2324
typeof(ExpanderAnimationsHelper),
24-
new PropertyMetadata("ExpanderContent"));
25+
new PropertyMetadata(DefaultAnimationTargetPartName));
2526

2627
#endregion
2728

@@ -176,6 +177,8 @@ private static void AnimateExpand(Expander expander)
176177
{
177178
var toAnimateControl = GetToAnimateControl(expander);
178179
toAnimateControl.BeginAnimation(UIElement.VisibilityProperty, null);
180+
toAnimateControl.Visibility = Visibility.Visible;
181+
179182
UpdateLayout(toAnimateControl);
180183

181184
if (toAnimateControl.RenderTransform is not TranslateTransform translateTransform)
@@ -270,7 +273,11 @@ private static void UpdateLayout(FrameworkElement contentControl)
270273
contentControl.UpdateLayout();
271274
}
272275

273-
private static FrameworkElement GetToAnimateControl(Expander expander) =>
274-
expander.Template?.FindName(GetToAnimateControlName(expander), expander) as FrameworkElement;
276+
private static FrameworkElement GetToAnimateControl(Expander expander)
277+
{
278+
expander.ApplyTemplate();
279+
return expander.Template?.FindName(GetToAnimateControlName(expander), expander) as FrameworkElement ??
280+
throw new InvalidOperationException($"Couldn't find the part to animate. Either update ExpanderAnimationsHelper.ToAnimateControlName, or rename the animation target part to the default: {DefaultAnimationTargetPartName}");
281+
}
275282
}
276283
}

0 commit comments

Comments
 (0)