|
| 1 | +namespace DevWinUI; |
| 2 | + |
| 3 | +public partial class AnimationPath |
| 4 | +{ |
| 5 | + public TimeSpan Duration |
| 6 | + { |
| 7 | + get { return (TimeSpan)GetValue(DurationProperty); } |
| 8 | + set { SetValue(DurationProperty, value); } |
| 9 | + } |
| 10 | + |
| 11 | + public static readonly DependencyProperty DurationProperty = |
| 12 | + DependencyProperty.Register(nameof(Duration), typeof(TimeSpan), typeof(AnimationPath), new PropertyMetadata(TimeSpan.FromSeconds(6), OnDurationChanged)); |
| 13 | + |
| 14 | + private static void OnDurationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 15 | + { |
| 16 | + if (d is AnimationPath ctl && ctl._shape != null) |
| 17 | + ctl.AnimateStroke(ctl._length); |
| 18 | + } |
| 19 | + |
| 20 | + public AnimationIterationBehavior RepeatBehavior |
| 21 | + { |
| 22 | + get { return (AnimationIterationBehavior)GetValue(RepeatBehaviorProperty); } |
| 23 | + set { SetValue(RepeatBehaviorProperty, value); } |
| 24 | + } |
| 25 | + |
| 26 | + public static readonly DependencyProperty RepeatBehaviorProperty = |
| 27 | + DependencyProperty.Register(nameof(RepeatBehavior), typeof(AnimationIterationBehavior), typeof(AnimationPath), new PropertyMetadata(AnimationIterationBehavior.Forever, OnRepeatBehaviorChanged)); |
| 28 | + |
| 29 | + private static void OnRepeatBehaviorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 30 | + { |
| 31 | + if (d is AnimationPath ctl && ctl._shape != null) |
| 32 | + ctl.AnimateStroke(ctl._length); |
| 33 | + } |
| 34 | + |
| 35 | + public string Data |
| 36 | + { |
| 37 | + get { return (string)GetValue(DataProperty); } |
| 38 | + set { SetValue(DataProperty, value); } |
| 39 | + } |
| 40 | + |
| 41 | + public static readonly DependencyProperty DataProperty = |
| 42 | + DependencyProperty.Register(nameof(Data), typeof(string), typeof(AnimationPath), new PropertyMetadata(null, OnDataChanged)); |
| 43 | + |
| 44 | + private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 45 | + { |
| 46 | + if (d is AnimationPath ctl && ctl.hostBorder != null) |
| 47 | + ctl.Init(); |
| 48 | + } |
| 49 | + |
| 50 | + public double StrokeThickness |
| 51 | + { |
| 52 | + get { return (double)GetValue(StrokeThicknessProperty); } |
| 53 | + set { SetValue(StrokeThicknessProperty, value); } |
| 54 | + } |
| 55 | + |
| 56 | + public static readonly DependencyProperty StrokeThicknessProperty = |
| 57 | + DependencyProperty.Register(nameof(StrokeThickness), typeof(double), typeof(AnimationPath), new PropertyMetadata(10.0d, OnStrokeThicknessChanged)); |
| 58 | + |
| 59 | + private static void OnStrokeThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 60 | + { |
| 61 | + if (d is AnimationPath ctl && ctl._shape != null) |
| 62 | + ctl._shape.StrokeThickness = (float)(double)e.NewValue; |
| 63 | + } |
| 64 | + |
| 65 | + public new Brush Foreground |
| 66 | + { |
| 67 | + get { return (Brush)GetValue(ForegroundProperty); } |
| 68 | + set { SetValue(ForegroundProperty, value); } |
| 69 | + } |
| 70 | + |
| 71 | + public new static readonly DependencyProperty ForegroundProperty = |
| 72 | + DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(AnimationPath), new PropertyMetadata(null, OnForegroundChanged)); |
| 73 | + |
| 74 | + private static void OnForegroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 75 | + { |
| 76 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 77 | + { |
| 78 | + Color color = ctl.GetColorFromBrush(); |
| 79 | + ctl._shape.StrokeBrush = ctl._compositor.CreateColorBrush(color); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + public CompositionStrokeCap StrokeStartCap |
| 84 | + { |
| 85 | + get { return (CompositionStrokeCap)GetValue(StrokeStartCapProperty); } |
| 86 | + set { SetValue(StrokeStartCapProperty, value); } |
| 87 | + } |
| 88 | + |
| 89 | + public static readonly DependencyProperty StrokeStartCapProperty = |
| 90 | + DependencyProperty.Register(nameof(StrokeStartCap), typeof(CompositionStrokeCap), typeof(AnimationPath), new PropertyMetadata(CompositionStrokeCap.Flat, OnStrokeStartCapChanged)); |
| 91 | + |
| 92 | + private static void OnStrokeStartCapChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 93 | + { |
| 94 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 95 | + { |
| 96 | + ctl._shape.StrokeStartCap = (CompositionStrokeCap)e.NewValue; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + public double StrokeMiterLimit |
| 101 | + { |
| 102 | + get { return (double)GetValue(StrokeMiterLimitProperty); } |
| 103 | + set { SetValue(StrokeMiterLimitProperty, value); } |
| 104 | + } |
| 105 | + |
| 106 | + public static readonly DependencyProperty StrokeMiterLimitProperty = |
| 107 | + DependencyProperty.Register(nameof(StrokeMiterLimit), typeof(double), typeof(AnimationPath), new PropertyMetadata(1.0d, OnStrokeMiterLimitChanged)); |
| 108 | + |
| 109 | + private static void OnStrokeMiterLimitChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 110 | + { |
| 111 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 112 | + { |
| 113 | + ctl._shape.StrokeMiterLimit = (float)(double)e.NewValue; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + public CompositionStrokeCap StrokeEndCap |
| 118 | + { |
| 119 | + get { return (CompositionStrokeCap)GetValue(StrokeEndCapProperty); } |
| 120 | + set { SetValue(StrokeEndCapProperty, value); } |
| 121 | + } |
| 122 | + |
| 123 | + public static readonly DependencyProperty StrokeEndCapProperty = |
| 124 | + DependencyProperty.Register(nameof(StrokeEndCap), typeof(CompositionStrokeCap), typeof(AnimationPath), new PropertyMetadata(CompositionStrokeCap.Flat, OnStrokeEndCapChanged)); |
| 125 | + |
| 126 | + private static void OnStrokeEndCapChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 127 | + { |
| 128 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 129 | + { |
| 130 | + ctl._shape.StrokeEndCap = (CompositionStrokeCap)e.NewValue; |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + public double StrokeDashOffset |
| 135 | + { |
| 136 | + get { return (double)GetValue(StrokeDashOffsetProperty); } |
| 137 | + set { SetValue(StrokeDashOffsetProperty, value); } |
| 138 | + } |
| 139 | + |
| 140 | + public static readonly DependencyProperty StrokeDashOffsetProperty = |
| 141 | + DependencyProperty.Register(nameof(StrokeDashOffset), typeof(double), typeof(AnimationPath), new PropertyMetadata(default(double), OnStrokeDashOffsetChanged)); |
| 142 | + |
| 143 | + private static void OnStrokeDashOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 144 | + { |
| 145 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 146 | + { |
| 147 | + ctl._shape.StrokeDashOffset = (float)(double)e.NewValue; |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + public CompositionStrokeCap StrokeDashCap |
| 152 | + { |
| 153 | + get { return (CompositionStrokeCap)GetValue(StrokeDashCapProperty); } |
| 154 | + set { SetValue(StrokeDashCapProperty, value); } |
| 155 | + } |
| 156 | + |
| 157 | + public static readonly DependencyProperty StrokeDashCapProperty = |
| 158 | + DependencyProperty.Register(nameof(StrokeDashCap), typeof(CompositionStrokeCap), typeof(AnimationPath), new PropertyMetadata(CompositionStrokeCap.Flat, OnStrokeDashCapChanged)); |
| 159 | + |
| 160 | + private static void OnStrokeDashCapChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 161 | + { |
| 162 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 163 | + { |
| 164 | + ctl._shape.StrokeDashCap = (CompositionStrokeCap)e.NewValue; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + public CompositionStrokeLineJoin StrokeLineJoin |
| 169 | + { |
| 170 | + get { return (CompositionStrokeLineJoin)GetValue(StrokeLineJoinProperty); } |
| 171 | + set { SetValue(StrokeLineJoinProperty, value); } |
| 172 | + } |
| 173 | + |
| 174 | + public static readonly DependencyProperty StrokeLineJoinProperty = |
| 175 | + DependencyProperty.Register(nameof(StrokeLineJoin), typeof(CompositionStrokeLineJoin), typeof(AnimationPath), new PropertyMetadata(CompositionStrokeLineJoin.Miter, OnStrokeLineJoinChanged)); |
| 176 | + |
| 177 | + private static void OnStrokeLineJoinChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 178 | + { |
| 179 | + if (d is AnimationPath ctl && ctl._shape != null && ctl._compositor != null) |
| 180 | + { |
| 181 | + ctl._shape.StrokeLineJoin = (CompositionStrokeLineJoin)e.NewValue; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + public bool IsPlaying |
| 186 | + { |
| 187 | + get => (bool)GetValue(IsPlayingProperty); |
| 188 | + set => SetValue(IsPlayingProperty, value); |
| 189 | + } |
| 190 | + public static readonly DependencyProperty IsPlayingProperty = |
| 191 | + DependencyProperty.Register(nameof(IsPlaying), typeof(bool), typeof(AnimationPath), new PropertyMetadata(true, OnIsPlayingChanged)); |
| 192 | + |
| 193 | + private static void OnIsPlayingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 194 | + { |
| 195 | + var ctl = (AnimationPath)d; |
| 196 | + ctl.HandleAnimationState(); |
| 197 | + } |
| 198 | +} |
0 commit comments