如何在FrameworkElement中将网格的边距与动画绑定

时间:2019-08-07 08:48:29

标签: wpf

我想用动画绑定网格的边距。 但是我在“ System.Windows.Media.Animation.DoubleAnimation”和 'System.Windows.Thickness'

这是我的C#代码

     public class Clamp_AnimatorChange : FrameworkElement
        {
            public static readonly DependencyProperty Clamp_SourceValueProperty =
        DependencyProperty.Register("Clamp_SourceValue", typeof(Thickness), typeof(Clamp_AnimatorChange));

            public Thickness Clamp_SourceValue
            {
                get
                {
                    return (Thickness)GetValue(Clamp_SourceValueProperty);
                }
                set
                {
                    SetValue(Clamp_SourceValueProperty, value);
                }
            }

            public static readonly DependencyProperty Clamp_TargetValueProperty =
                 DependencyProperty.Register("Clamp_TargetValue", typeof(double), typeof(Clamp_AnimatorChange),
                 new PropertyMetadata(0.0,
                     (s, e) =>
                     {
                         Clamp_AnimatorChange me = (Clamp_AnimatorChange)s;
                         double Value1 = (((double)e.NewValue ) *8)-5;
                         me.BeginAnimation(Clamp_SourceValueProperty,
                             new DoubleAnimation(
                                 Value1,
                                 new Duration(TimeSpan.FromSeconds(0.1))), HandoffBehavior.SnapshotAndReplace);
                     }
                     )
                 );

            public double Clamp_TargetValue
            {
                get
                {
                    return (double)GetValue(Clamp_TargetValueProperty);
                }
                set
                {
                    SetValue(Clamp_TargetValueProperty, value);
                }
            }
        }

这是我的xaml代码

0 个答案:

没有答案