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
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
Expand All @@ -17,11 +16,13 @@ public static string GetToAnimateControlName(Expander element) =>
public static void SetToAnimateControlName(Expander element, string value) =>
element.SetValue(ToAnimateControlNameProperty, value);

private const string DefaultAnimationTargetPartName = "ExpanderContent";

public static readonly DependencyProperty ToAnimateControlNameProperty = DependencyProperty.RegisterAttached(
"ToAnimateControlName",
typeof(string),
typeof(ExpanderAnimationsHelper),
new PropertyMetadata("ExpanderContent"));
new PropertyMetadata(DefaultAnimationTargetPartName));

#endregion

Expand Down Expand Up @@ -176,6 +177,8 @@ 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 Expand Up @@ -270,7 +273,11 @@ private static void UpdateLayout(FrameworkElement contentControl)
contentControl.UpdateLayout();
}

private static FrameworkElement GetToAnimateControl(Expander expander) =>
expander.Template?.FindName(GetToAnimateControlName(expander), expander) as FrameworkElement;
private static FrameworkElement GetToAnimateControl(Expander expander)
{
expander.ApplyTemplate();
return expander.Template?.FindName(GetToAnimateControlName(expander), expander) as FrameworkElement ??
throw new InvalidOperationException($"Couldn't find the part to animate. Either update ExpanderAnimationsHelper.ToAnimateControlName, or rename the animation target part to the default: {DefaultAnimationTargetPartName}");
}
}
}
Loading