Files
DP44/Common/DTS.CommonCore/Controls/GridLengthAnimation.cs
2026-04-17 14:55:32 -04:00

52 lines
1.7 KiB
C#

using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace DTS.Common.Controls
{
public class GridLengthAnimation : AnimationTimeline
{
public GridLengthAnimation()
{
// no-op
}
public GridLength From
{
get => (GridLength)GetValue(FromProperty);
set => SetValue(FromProperty, value);
}
public static readonly DependencyProperty FromProperty =
DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));
public GridLength To
{
get => (GridLength)GetValue(ToProperty);
set => SetValue(ToProperty, value);
}
public static readonly DependencyProperty ToProperty =
DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));
public override Type TargetPropertyType => typeof(GridLength);
protected override Freezable CreateInstanceCore()
{
return new GridLengthAnimation();
}
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
{
var fromValue = From.Value;
var toValue = To.Value;
if (fromValue > toValue)
{
return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromValue - toValue) + toValue, To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
}
return new GridLength(animationClock.CurrentProgress.Value * (toValue - fromValue) + fromValue, To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
}
}
}