自定义「属性故事面板」与「属性设置动画」
This commit is contained in:
41
RazorEngineTest/PropertySetterAnimation.cs
Normal file
41
RazorEngineTest/PropertySetterAnimation.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user