自定义「属性故事面板」与「属性设置动画」

This commit is contained in:
于智纯
2025-09-07 21:09:03 +08:00
parent 7212a7dea7
commit a023c7f6cb
3 changed files with 90 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
namespace RazorEngineTest
{
public class PropertySetterAnimation : AnimationTimeline
{
// 定义依赖属性用于绑定目标值
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(object), typeof(PropertySetterAnimation));
public object Value
{
get { return GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
// 指定目标属性类型(可设置为任意类型)
public override Type TargetPropertyType => typeof(object);
// 创建动画实例
protected override Freezable CreateInstanceCore() => new PropertySetterAnimation();
// 核心方法:返回固定值(无插值过程)
public override object GetCurrentValue(
object defaultOriginValue,
object defaultDestinationValue,
AnimationClock animationClock)
{
return Value; // 直接返回预设值
}
// 可选:设置是否使用动画插值
public bool IsAnimationEnabled { get; set; } = false;
}
}