diff --git a/RazorEngineTest/PropertySetterAnimation.cs b/RazorEngineTest/PropertySetterAnimation.cs new file mode 100644 index 0000000..a27efbd --- /dev/null +++ b/RazorEngineTest/PropertySetterAnimation.cs @@ -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; + } +} diff --git a/RazorEngineTest/PropertyStoryboard.cs b/RazorEngineTest/PropertyStoryboard.cs new file mode 100644 index 0000000..21cbbc2 --- /dev/null +++ b/RazorEngineTest/PropertyStoryboard.cs @@ -0,0 +1,46 @@ +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 PropertyStoryboard : Storyboard + { + private readonly SetterBaseCollection _setters = new SetterBaseCollection(); + + public SetterBaseCollection Setters => _setters; + public new void Begin() + { + base.Begin(); + ApplyPropertySetters(); + } + + private void ApplyPropertySetters() + { + foreach (SetterBase setterBase in _setters) + { + if (setterBase is Setter setter && GetTarget(setter.TargetName) is DependencyObject targetObject) + { + DependencyProperty property = setter.Property; + object value = setter.Value; + + if (property != null) + { + targetObject.SetValue(property, value); + } + } + } + } + + // 快捷添加Setter的方法 + public void AddSetter(DependencyProperty property, object value) + { + _setters.Add(new Setter(property, value)); + } + public DependencyObject GetTarget(string targetName) => throw new NotImplementedException(); + } +} diff --git a/RazorEngineTest/Themes/Generic.xaml b/RazorEngineTest/Themes/Generic.xaml index a73f963..a860c72 100644 --- a/RazorEngineTest/Themes/Generic.xaml +++ b/RazorEngineTest/Themes/Generic.xaml @@ -30,7 +30,8 @@ - @@ -50,6 +51,7 @@ +