■ DoubleAnimationBase 클래스를 사용해 커스컴 애니메이션을 만드는 방법을 보여준다.
▶ BackDirectionAnimation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
using System; using System.Windows; using System.Windows.Media.Animation; namespace TestProject { /// <summary> /// 반대 방향 애니메이션 /// </summary> public class BackDirectionAnimation : DoubleAnimationBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 타입 - EdgeBehaviorType /// <summary> /// 모서리 동작 타입 /// </summary> public enum EdgeBehaviorType { /// <summary> /// EASE IN /// </summary> EaseIn, /// <summary> /// EASE OUT /// </summary> EaseOut, /// <summary> /// EASE IN/OUT /// </summary> EaseInOut } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 속성 - EdgeBehaviorProperty /// <summary> /// 모서리 동작 속성 /// </summary> public static readonly DependencyProperty EdgeBehaviorProperty = DependencyProperty.Register ( "EdgeBehavior", typeof(EdgeBehaviorType), typeof(BackDirectionAnimation), new PropertyMetadata(EdgeBehaviorType.EaseIn) ); #endregion #region 진폭 속성 - AmplitudeProperty /// <summary> /// 진폭 속성 /// </summary> public static readonly DependencyProperty AmplitudeProperty = DependencyProperty.Register ( "Amplitude", typeof(double), typeof(BackDirectionAnimation), new PropertyMetadata(4.0) ); #endregion #region 억제 속성 - SuppressionProperty /// <summary> /// 억제 속성 /// </summary> public static readonly DependencyProperty SuppressionProperty = DependencyProperty.Register ( "Suppression", typeof(double), typeof(BackDirectionAnimation), new PropertyMetadata(2.0) ); #endregion #region 시작 값 속성 - FromProperty /// <summary> /// 시작 값 속성 /// </summary> public static readonly DependencyProperty FromProperty = DependencyProperty.Register ( "From", typeof(double?), typeof(BackDirectionAnimation), new PropertyMetadata(null) ); #endregion #region 종료 값 속성 - ToProperty /// <summary> /// 종료 값 속성 /// </summary> public static readonly DependencyProperty ToProperty = DependencyProperty.Register ( "To", typeof(double?), typeof(BackDirectionAnimation), new PropertyMetadata(null) ); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 - EdgeBehavior /// <summary> /// 모서리 동작 /// </summary> public EdgeBehaviorType EdgeBehavior { get { return (EdgeBehaviorType)GetValue(EdgeBehaviorProperty); } set { SetValue(EdgeBehaviorProperty, value); } } #endregion #region 진폭 - Amplitude /// <summary> /// 진폭 /// </summary> public double Amplitude { get { return (double)GetValue(AmplitudeProperty); } set { SetValue(AmplitudeProperty, value); } } #endregion #region 억제 - Suppression /// <summary> /// 억제 /// </summary> public double Suppression { get { return (double)GetValue(SuppressionProperty); } set { SetValue(SuppressionProperty, value); } } #endregion #region 시작 값 - From /// <summary> /// 시작 값 /// </summary> public double? From { get { return (double?)GetValue(FromProperty); } set { SetValue(FromProperty, value); } } #endregion #region 종료 값 - To /// <summary> /// 종료 값 /// </summary> public double? To { get { return (double?)GetValue(ToProperty); } set { SetValue(ToProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 인스턴스 생성하기 (코어) - CreateInstanceCore() /// <summary> /// 인스턴스 생성하기 (코어) /// </summary> /// <returns></returns> protected override Freezable CreateInstanceCore() => new BackDirectionAnimation(); #endregion #region 현재 값 구하기 (코어) - GetCurrentValueCore(defaultSourceValue, defaultTargetValue, clock) /// <summary> /// 현재 값 구하기 (코어) /// </summary> /// <param name="defaultSourceValue">디폴트 시작 값</param> /// <param name="defaultTargetValue">디폴트 종료 값</param> /// <param name="clock">애니메이션 클럭</param> /// <returns>현재 값</returns> protected override double GetCurrentValueCore(double defaultSourceValue, double defaultTargetValue, AnimationClock clock) { double value; var start = From ?? defaultSourceValue; var delta = To - start ?? defaultSourceValue - start; switch(EdgeBehavior) { case EdgeBehaviorType.EaseIn : value = EaseIn(clock.CurrentProgress.Value, start, delta, Amplitude, Suppression); break; case EdgeBehaviorType.EaseOut : value = EaseOut(clock.CurrentProgress.Value, start, delta, Amplitude, Suppression); break; default : value = EaseInOut(clock.CurrentProgress.Value, start, delta, Amplitude, Suppression); break; } return value; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region EASE IN 처리하기 - EaseIn(timeFraction, start, delta, amplitude, suppression) /// <summary> /// EASE IN 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="amplitude">진폭</param> /// <param name="suppression">억제</param> /// <returns>처리 결과</returns> private double EaseIn(double timeFraction, double start, double delta, double amplitude, double suppression) { double frequency = 0.5; double value = Math.Pow(1 - timeFraction, suppression) * amplitude * Math.Sin(2 * Math.PI * timeFraction*frequency) * -1 + timeFraction; value = value * delta; value += start; return value; } #endregion #region EASE OUT 처리하기 - EaseOut(timeFraction, start, delta, amplitude, suppression) /// <summary> /// EASE OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="amplitude">진폭</param> /// <param name="suppression">억제</param> /// <returns>처리 결과</returns> private double EaseOut(double timeFraction, double start, double delta, double amplitude, double suppression) { double frequency = 0.5; double value = Math.Pow(timeFraction, suppression) * amplitude * Math.Sin(2 * Math.PI * timeFraction * frequency) + timeFraction; value = value * delta; value += start; return value; } #endregion #region EASE IN/OUT 처리하기 - EaseInOut(timeFraction, start, delta, amplitude, suppression) /// <summary> /// EASE IN/OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="amplitude">진폭</param> /// <param name="suppression">억제</param> /// <returns>처리 결과</returns> private double EaseInOut(double timeFraction, double start, double delta, double amplitude, double suppression) { double returnValue; if(timeFraction <= 0.5) { return EaseIn(timeFraction * 2, start, delta / 2, amplitude, suppression); } returnValue = EaseOut((timeFraction - 0.5) * 2, start, delta / 2, amplitude, suppression); returnValue += delta / 2; return returnValue; } #endregion } } |
▶ BounceAnimation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
using System; using System.Windows; using System.Windows.Media.Animation; namespace TestProject { /// <summary> /// 바운스 애니메이션 /// </summary> public class BounceAnimation : DoubleAnimationBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 타입 - EdgeBehaviorType /// <summary> /// 모서리 동작 타입 /// </summary> public enum EdgeBehaviorType { /// <summary> /// EASE IN /// </summary> EaseIn, /// <summary> /// EASE OUT /// </summary> EaseOut, /// <summary> /// EASE IN/OUT /// </summary> EaseInOut } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 속성 - EdgeBehaviorProperty /// <summary> /// 모서리 동작 속성 /// </summary> public static readonly DependencyProperty EdgeBehaviorProperty = DependencyProperty.Register ( "EdgeBehavior", typeof(EdgeBehaviorType), typeof(BounceAnimation), new PropertyMetadata(EdgeBehaviorType.EaseInOut) ); #endregion #region 바운스 카운트 속성 - BounceCountProperty /// <summary> /// 바운스 카운트 속성 /// </summary> public static readonly DependencyProperty BounceCountProperty = DependencyProperty.Register ( "BounceCount", typeof(int), typeof(BounceAnimation), new PropertyMetadata(5) ); #endregion #region 탄력도 속성 - BouncinessProperty /// <summary> /// 탄력도 속성 /// </summary> public static readonly DependencyProperty BouncinessProperty = DependencyProperty.Register ( "Bounciness", typeof(double), typeof(BounceAnimation), new PropertyMetadata(3.0) ); #endregion #region 시작 값 속성 - FromProperty /// <summary> /// From 시작 값 /// </summary> public static readonly DependencyProperty FromProperty = DependencyProperty.Register ( "From", typeof(double?), typeof(BounceAnimation), new PropertyMetadata(null) ); #endregion #region 종료 값 속성 - ToProperty /// <summary> /// 종료 값 속성 /// </summary> public static readonly DependencyProperty ToProperty = DependencyProperty.Register ( "To", typeof(double?), typeof(BounceAnimation), new PropertyMetadata(null) ); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 - EdgeBehavior /// <summary> /// 모서리 동작 /// </summary> public EdgeBehaviorType EdgeBehavior { get { return (EdgeBehaviorType)GetValue(EdgeBehaviorProperty); } set { SetValue(EdgeBehaviorProperty, value); } } #endregion #region 바운스 카운트 - BounceCount /// <summary> /// 바운스 카운트 /// </summary> public int BounceCount { get { return (int)GetValue(BounceCountProperty); } set { if(value > 0) { SetValue(BounceCountProperty, value); } else { throw new ArgumentException($"바운스 카운트를 설정할 수 없습니다 : {value}"); } } } #endregion #region 탄력도 - Bounciness /// <summary> /// 탄력도 /// </summary> public double Bounciness { get { return (double)GetValue(BouncinessProperty); } set { if(value > 0) { SetValue(BouncinessProperty, value); } else { throw new ArgumentException($"탄력도를 설정할 수 없습니다 : {value}"); } } } #endregion #region 시작값 - From /// <summary> /// 시작값 /// </summary> public double? From { get { return (double?)GetValue(FromProperty); } set { SetValue(FromProperty, value); } } #endregion #region 종료값 - To /// <summary> /// 종료값 /// </summary> public double? To { get { return (double?)GetValue(ToProperty); } set { SetValue(ToProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 인스턴스 생성하기 (코어) - CreateInstanceCore() /// <summary> /// 인스턴스 생성하기 (코어) /// </summary> /// <returns>생성 인스턴스</returns> protected override Freezable CreateInstanceCore() => new BounceAnimation(); #endregion #region 현재 값 구하기 (코어) - GetCurrentValueCore(defaultSourceValue, defaultTargetValue, clock) /// <summary> /// 현재 값 구하기 (코어) /// </summary> /// <param name="defaultSourceValue">디폴트 소스 값</param> /// <param name="defaultTargetValue">디폴트 타겟 값</param> /// <param name="clock">애니메이션 클럭</param> /// <returns>현재 값</returns> protected override double GetCurrentValueCore(double defaultSourceValue, double defaultTargetValue, AnimationClock clock) { double value; double start = From ?? defaultSourceValue; double delta = To - start ?? defaultSourceValue - start; switch(EdgeBehavior) { case EdgeBehaviorType.EaseIn : value = EaseIn(clock.CurrentProgress.Value, start, delta, Bounciness, BounceCount); break; case EdgeBehaviorType.EaseOut : value = EaseOut(clock.CurrentProgress.Value, start, delta, Bounciness, BounceCount); break; default : value = EaseInOut(clock.CurrentProgress.Value, start, delta, Bounciness, BounceCount); break; } return value; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region EASE OUT 처리하기 - EaseOut(timeFraction, start, delta, bounciness, bounceCount) /// <summary> /// EASE OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="bounciness">탄력도</param> /// <param name="bounceCount">바운스 카운트</param> /// <returns>처리 결과</returns> private double EaseOut(double timeFraction, double start, double delta, double bounciness, int bounceCount) { double value = Math.Abs(Math.Pow(1 - timeFraction, bounciness) * Math.Cos(2 * Math.PI * timeFraction * bounceCount)); value = delta - (value * delta); value += start; return value; } #endregion #region EASE IN 처리하기 - EaseIn(timeFraction, start, delta, bounciness, bounceCount) /// <summary> /// EASE IN 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="bounciness">탄력도</param> /// <param name="bounceCount">바운스 카운트</param> /// <returns>처리 결과</returns> private double EaseIn(double timeFraction, double start, double delta, double bounciness, int bounceCount) { double value = Math.Abs(Math.Pow(timeFraction, bounciness) * Math.Cos(2 * Math.PI * timeFraction * bounceCount)); value = value * delta; value += start; return value; } #endregion #region EASE IN/OUT 처리하기 - EaseInOut(timeFraction, start, delta, bounciness, bounceCount) /// <summary> /// EASE IN/OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="bounciness">탄력도</param> /// <param name="bounceCount">바운스 카운트</param> /// <returns>처리 결과</returns> private double EaseInOut(double timeFraction, double start, double delta, double bounciness, int bounceCount) { double value; if(timeFraction <= 0.5) { value = EaseIn(timeFraction * 2, start, delta / 2, bounciness, bounceCount); } else { value = EaseOut((timeFraction - 0.5) * 2, start, delta / 2, bounciness, bounceCount); value += delta / 2; } return value; } #endregion } } |
▶ CircleAnimation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
using System; using System.Windows; using System.Windows.Media.Animation; namespace TestProject { /// <summary> /// 원 애니메이션 /// </summary> public class CircleAnimation : DoubleAnimationBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 방향 타입 - DirectionType /// <summary> /// 방향 타입 /// </summary> public enum DirectionType { /// <summary> /// X 방향 /// </summary> XDirection, /// <summary> /// Y 방향 /// </summary> YDirection } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 반경 속성 - DependencyProperty /// <summary> /// 반경 속성 /// </summary> public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register ( "Radius", typeof(double), typeof(CircleAnimation), new PropertyMetadata((double) 10) ); #endregion #region 방향 속성 - DirectionProperty /// <summary> /// 방향 속성 /// </summary> public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register ( "Direction", typeof(DirectionType), typeof(CircleAnimation), new PropertyMetadata(DirectionType.XDirection) ); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 반경 - Radius /// <summary> /// 반경 /// </summary> public double Radius { get { return (double)GetValue(RadiusProperty); } set { if(value > 0.0) { SetValue(RadiusProperty, value); } else { throw new ArgumentException($"허용되지 않는 반경입니다 : {value}"); } } } #endregion #region 방향 - Direction /// <summary> /// 방향 /// </summary> public DirectionType Direction { get { return (DirectionType)GetValue(DirectionProperty); } set { SetValue(DirectionProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 인스턴스 생성하기 (코어) - CreateInstanceCore() /// <summary> /// 인스턴스 생성하기 (코어) /// </summary> /// <returns>생성 인스턴스</returns> protected override Freezable CreateInstanceCore() => new CircleAnimation(); #endregion #region 현재 값 구하기 (코어) - GetCurrentValueCore(defaultSourceValue, defaultTargetValue, clock) /// <summary> /// 현재 값 구하기 (코어) /// </summary> /// <param name="defaultSourceValue">디폴트 소스 값</param> /// <param name="defaultTargetValue">디폴트 타겟 값</param> /// <param name="clock">애니메이션 클럭</param> /// <returns>현재 값</returns> protected override double GetCurrentValueCore(double defaultSourceValue, double defaultTargetValue, AnimationClock clock) { double time = clock.CurrentProgress.Value; double value = Direction == DirectionType.XDirection ? Math.Cos(2 * Math.PI * time) : Math.Sin(2 * Math.PI * time); return value * Radius + defaultSourceValue; } #endregion } } |
▶ ElasticAnimation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
using System; using System.Windows; using System.Windows.Media.Animation; namespace TestProject { /// <summary> /// 탄성 애니메이션 /// </summary> public class ElasticAnimation : DoubleAnimationBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 타입 - EdgeBehaviorType /// <summary> /// 모서리 동작 타입 /// </summary> public enum EdgeBehaviorType { /// <summary> /// EASE IN /// </summary> EaseIn, /// <summary> /// EASE OUT /// </summary> EaseOut, /// <summary> /// EASE IN/OUT /// </summary> EaseInOut } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 속성 - EdgeBehaviorProperty /// <summary> /// 모서리 동작 속성 /// </summary> public static readonly DependencyProperty EdgeBehaviorProperty = DependencyProperty.Register ( "EdgeBehavior", typeof(EdgeBehaviorType), typeof(ElasticAnimation), new PropertyMetadata(EdgeBehaviorType.EaseIn) ); #endregion #region 탄력도 속성 - SpringinessProperty /// <summary> /// 탄력도 속성 /// </summary> public static readonly DependencyProperty SpringinessProperty = DependencyProperty.Register ( "Springiness", typeof(double), typeof(ElasticAnimation), new PropertyMetadata(3.0) ); #endregion #region 진동 속성 - OscillationsProperty /// <summary> /// 진동 속성 /// </summary> public static readonly DependencyProperty OscillationsProperty = DependencyProperty.Register ( "Oscillations", typeof(double), typeof(ElasticAnimation), new PropertyMetadata(10.0) ); #endregion #region 시작 값 속성 - FromProperty /// <summary> /// 시작 값 속성 /// </summary> public static readonly DependencyProperty FromProperty = DependencyProperty.Register ( "From", typeof(double?), typeof(ElasticAnimation), new PropertyMetadata(null) ); #endregion #region 종료 값 속성 - ToProperty /// <summary> /// 종료 값 속성 /// </summary> public static readonly DependencyProperty ToProperty = DependencyProperty.Register ( "To", typeof(double?), typeof(ElasticAnimation), new PropertyMetadata(null) ); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 - EdgeBehavior /// <summary> /// 모서리 동작 /// </summary> public EdgeBehaviorType EdgeBehavior { get { return (EdgeBehaviorType)GetValue(EdgeBehaviorProperty); } set { SetValue(EdgeBehaviorProperty, value); } } #endregion #region 탄력도 - Springiness /// <summary> /// 탄력도 /// </summary> public double Springiness { get { return (double)GetValue(SpringinessProperty); } set { SetValue(SpringinessProperty, value); } } #endregion #region 진동 - Oscillations /// <summary> /// 진동 /// </summary> public double Oscillations { get { return (double)GetValue(OscillationsProperty); } set { SetValue(OscillationsProperty, value); } } #endregion #region 시작 값 - From /// <summary> /// 시작 값 /// </summary> public double? From { get { return (double?)GetValue(FromProperty); } set { SetValue(FromProperty, value); } } #endregion #region 종료 값 - To /// <summary> /// 종료 값 /// </summary> public double? To { get { return (double?)GetValue(ToProperty); } set { SetValue(ToProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 인스턴스 생성하기 (코어) - CreateInstanceCore() /// <summary> /// 인스턴스 생성하기 (코어) /// </summary> /// <returns>생성 인스턴스</returns> protected override Freezable CreateInstanceCore() => new ElasticAnimation(); #endregion #region 현재 값 구하기 (코어) - GetCurrentValueCore(defaultSourceValue, defaultTargetValue, clock) /// <summary> /// 현재 값 구하기 (코어) /// </summary> /// <param name="defaultSourceValue">디폴트 소스 값</param> /// <param name="defaultTargetValue">디폴트 타겟 값</param> /// <param name="clock">애니메이션 클럭</param> /// <returns>현재 값</returns> protected override double GetCurrentValueCore(double defaultSourceValue, double defaultTargetValue, AnimationClock clock) { double value; double start = From ?? defaultSourceValue; double delta = To - start ?? defaultSourceValue - start; switch(EdgeBehavior) { case EdgeBehaviorType.EaseIn : value = EaseIn(clock.CurrentProgress.Value, start, delta, Springiness, Oscillations); break; case EdgeBehaviorType.EaseOut : value = EaseOut(clock.CurrentProgress.Value, start, delta, Springiness, Oscillations); break; default : value = EaseInOut(clock.CurrentProgress.Value, start, delta, Springiness, Oscillations); break; } return value; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region EASE IN 처리하기 - EaseIn(timeFraction, start, delta, springiness, oscillations) /// <summary> /// EASE IN 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="springiness">탄력도</param> /// <param name="oscillations">진동</param> /// <returns>처리 결과</returns> private static double EaseIn(double timeFraction, double start, double delta, double springiness, double oscillations) { double value = Math.Pow(timeFraction, springiness) * Math.Cos(2 * Math.PI * timeFraction * oscillations); value = value * delta; value += start; return value; } #endregion #region EASE OUT 처리하기 - EaseOut(timeFraction, start, delta, springiness, oscillations) /// <summary> /// EASE OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="springiness">탄력도</param> /// <param name="oscillations">진동</param> /// <returns>처리 결과</returns> private static double EaseOut(double timeFraction, double start, double delta, double springiness, double oscillations) { double value = Math.Pow(1 - timeFraction, springiness) * Math.Cos(2 * Math.PI * timeFraction * oscillations); value = delta - (value * delta); value += start; return value; } #endregion #region EASE IN/OUT 처리하기 - EaseInOut(timeFraction, start, delta, springiness, oscillations) /// <summary> /// EASE IN/OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="springiness">탄력도</param> /// <param name="oscillations">진동</param> /// <returns>처리 결과</returns> private static double EaseInOut(double timeFraction, double start, double delta, double springiness, double oscillations) { double value; if(timeFraction <= 0.5) { return EaseIn(timeFraction * 2, start, delta / 2, springiness, oscillations); } value = EaseOut((timeFraction - 0.5) * 2, start, delta / 2, springiness, oscillations); value += delta / 2; return value; } #endregion } } |
▶ ExponentialAnimation.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
using System; using System.Windows; using System.Windows.Media.Animation; namespace TestProject { /// <summary> /// 지수 애니메이션 /// </summary> public class ExponentialAnimation : DoubleAnimationBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Enumeration ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 타입 - EdgeBehaviorType /// <summary> /// 모서리 동작 타입 /// </summary> public enum EdgeBehaviorType { /// <summary> /// EASE IN /// </summary> EaseIn, /// <summary> /// EASE OUT /// </summary> EaseOut, /// <summary> /// EASE IN/OUT /// </summary> EaseInOut } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 속성 - EdgeBehaviorProperty /// <summary> /// 모서리 동작 속성 /// </summary> public static readonly DependencyProperty EdgeBehaviorProperty = DependencyProperty.Register ( "EdgeBehavior", typeof(EdgeBehaviorType), typeof(ExponentialAnimation), new PropertyMetadata(EdgeBehaviorType.EaseIn) ); #endregion #region 거듭 제곱 속성 - PowerProperty /// <summary> /// 거듭 제곱 속성 /// </summary> public static readonly DependencyProperty PowerProperty = DependencyProperty.Register ( "Power", typeof(double), typeof(ExponentialAnimation), new PropertyMetadata(2.0) ); #endregion #region 시작 값 속성 - FromProperty /// <summary> /// 시작 값 속성 /// </summary> public static readonly DependencyProperty FromProperty = DependencyProperty.Register ( "From", typeof(double?), typeof(ExponentialAnimation), new PropertyMetadata(null) ); #endregion #region 종료 값 속성 - ToProperty /// <summary> /// 종료 값 속성 /// </summary> public static readonly DependencyProperty ToProperty = DependencyProperty.Register ( "To", typeof(double?), typeof(ExponentialAnimation), new PropertyMetadata(null) ); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 모서리 동작 - EdgeBehavior /// <summary> /// 모서리 동작 /// </summary> public EdgeBehaviorType EdgeBehavior { get { return (EdgeBehaviorType)GetValue(EdgeBehaviorProperty); } set { SetValue(EdgeBehaviorProperty, value); } } #endregion #region 거듭 제곱 - Power /// <summary> /// 거듭 제곱 /// </summary> public double Power { get { return (double)GetValue(PowerProperty); } set { if(value > 0.0) { SetValue(PowerProperty, value); } else { throw new ArgumentException($"0보다 작은 거듭제곱 값을 설정할 수 없습니다 : {value}"); } } } #endregion #region 시작 값 - From /// <summary> /// 시작 값 /// </summary> public double? From { get { return (double?)GetValue(FromProperty); } set { SetValue(FromProperty, value); } } #endregion #region 종료 값 - To /// <summary> /// 종료 값 /// </summary> public double? To { get { return (double?)GetValue(ToProperty); } set { SetValue(ToProperty, value); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 인스턴스 생성하기 (코어) - CreateInstanceCore() /// <summary> /// 인스턴스 생성하기 (코어) /// </summary> /// <returns>생성 인스턴스</returns> protected override Freezable CreateInstanceCore() => new ExponentialAnimation(); #endregion #region 현재 값 구하기 (코어) - GetCurrentValueCore(defaultSourceValue, defaultTargetValue, clock) /// <summary> /// 현재 값 구하기 (코어) /// </summary> /// <param name="defaultSourceValue">디폴트 소스 값</param> /// <param name="defaultTargetValue">디폴트 타겟 값</param> /// <param name="clock">애니메이션 클럭</param> /// <returns>현재 값</returns> protected override double GetCurrentValueCore(double defaultSourceValue, double defaultTargetValue, AnimationClock clock) { double value; double start = From ?? defaultSourceValue; double delta = To - start ?? defaultSourceValue - start; switch(EdgeBehavior) { case EdgeBehaviorType.EaseIn : value = EaseIn(clock.CurrentProgress.Value, start, delta, Power); break; case EdgeBehaviorType.EaseOut : value = EaseOut(clock.CurrentProgress.Value, start, delta, Power); break; default : value = EaseInOut(clock.CurrentProgress.Value, start, delta, Power); break; } return value; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region EASE IN 처리하기 - EaseIn(timeFraction, start, delta, power) /// <summary> /// EASE IN 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="power">거듭 제곱</param> /// <returns>처리 결과</returns> private double EaseIn(double timeFraction, double start, double delta, double power) { double value = Math.Pow(timeFraction, power); value *= delta; value = value + start; return value; } #endregion #region EASE OUT 처리하기 - EaseOut(timeFraction, start, delta, power) /// <summary> /// EASE OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="power">거듭 제곱</param> /// <returns>처리 결과</returns> private double EaseOut(double timeFraction, double start, double delta, double power) { double value = Math.Pow(timeFraction, 1 / power); value *= delta; value = value + start; return value; } #endregion #region EASE IN/OUT 처리하기 - EaseInOut(timeFraction, start, delta, power) /// <summary> /// EASE IN/OUT 처리하기 /// </summary> /// <param name="timeFraction">시간 분할</param> /// <param name="start">시작 값</param> /// <param name="delta">증분</param> /// <param name="power">거듭 제곱</param> /// <returns>처리 결과</returns> private double EaseInOut(double timeFraction, double start, double delta, double power) { double value; if(timeFraction <= 0.5) { value = EaseOut(timeFraction * 2, start, delta / 2, power); } else { value = EaseIn((timeFraction - 0.5) * 2, start, delta / 2, power); value += delta / 2; } return value; } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestProject" Width="800" Height="800" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Storyboard x:Key="LinearStoryboardKey"> <DoubleAnimation Storyboard.TargetName="linearButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" /> </Storyboard> <Storyboard x:Key="AccelerateStoryboardKey"> <DoubleAnimation Storyboard.TargetName="accelerateButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" AccelerationRatio="0.65" /> </Storyboard> <Storyboard x:Key="DecelerateStoryboardKey"> <DoubleAnimation Storyboard.TargetName="decelerateButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" DecelerationRatio="0.65" /> </Storyboard> <Storyboard x:Key="AccelerateDecelerateStoryboardKey"> <DoubleAnimation Storyboard.TargetName="accelerateDecelerateButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" AccelerationRatio="0.325" DecelerationRatio="0.325" /> </Storyboard> <Storyboard x:Key="EaseInBounceStoryboardKey"> <local:BounceAnimation Storyboard.TargetName="easeInBounceButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseIn" /> </Storyboard> <Storyboard x:Key="EaseOutBounceStoryboardKey"> <local:BounceAnimation Storyboard.TargetName="easeOutBounceButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseOut" /> </Storyboard> <Storyboard x:Key="EaseInOutBounceStoryboardKey"> <local:BounceAnimation Storyboard.TargetName="easeInOutBounceButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseInOut" /> </Storyboard> <Storyboard x:Key="EaseInElasticStoryboardKey"> <local:ElasticAnimation Storyboard.TargetName="easeInElasticButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseIn" /> </Storyboard> <Storyboard x:Key="EaseOutElasticStoryboardKey"> <local:ElasticAnimation Storyboard.TargetName="easeOutElasticButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseOut" /> </Storyboard> <Storyboard x:Key="EaseInOutElasticStoryboardKey"> <local:ElasticAnimation Storyboard.TargetName="easeInOutElasticButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseInOut" /> </Storyboard> <Storyboard x:Key="EaseInExponentialStoryboardKey"> <local:ExponentialAnimation Storyboard.TargetName="easeInExponentialButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseIn" Power="2" /> </Storyboard> <Storyboard x:Key="EaseOutExponentialStoryboardKey"> <local:ExponentialAnimation Storyboard.TargetName="easeOutExponentialButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseOut" Power="4" /> </Storyboard> <Storyboard x:Key="EaseInOutExponentialStoryboardKey"> <local:ExponentialAnimation Storyboard.TargetName="easeInOutExponentialButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseInOut" Power="6" /> </Storyboard> <Storyboard x:Key="EaseInBackDirectionStoryboardKey"> <local:BackDirectionAnimation Storyboard.TargetName="easeInBackDirectionButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseIn" Amplitude="1" Suppression="3" /> </Storyboard> <Storyboard x:Key="EaseOutBackDirectionStoryboardKey"> <local:BackDirectionAnimation Storyboard.TargetName="easeOutBackDirectionButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseOut" Amplitude="2" Suppression="5" /> </Storyboard> <Storyboard x:Key="EaseInOutBackDirectionStoryboardKey"> <local:BackDirectionAnimation Storyboard.TargetName="easeInOutBackDirectionButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" EdgeBehavior="EaseInOut" Amplitude="3" Suppression="0.5" /> </Storyboard> <Storyboard x:Key="CircleStoryboardKey1"> <DoubleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:05" From="0" To="500" /> <DoubleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="00:00:01.5" From="0" /> <ParallelTimeline BeginTime="00:00:00" Duration="00:00:04.5"> <local:CircleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:01" RepeatBehavior="Forever" Radius="40" Direction="XDirection" /> <local:CircleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="00:00:01" RepeatBehavior="Forever" Radius="40" Direction="YDirection" /> </ParallelTimeline> <ParallelTimeline BeginTime="00:00:04.5"> <DoubleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:00.5" To="500" /> <DoubleAnimation Storyboard.TargetName="circleButton1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="00:00:00.5" To="0.0" /> </ParallelTimeline> </Storyboard> <Storyboard x:Key="CircleStoryboardKey2"> <DoubleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:01.5" From="0" To="290" /> <DoubleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="0:0:1.5" From="0" /> <ParallelTimeline BeginTime="00:00:01.5" Duration="00:00:02"> <local:CircleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:00.25" RepeatBehavior="Forever" Radius="40" Direction="XDirection" /> <local:CircleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="00:00:00.25" RepeatBehavior="Forever" Radius="40" Direction="YDirection" /> </ParallelTimeline> <ParallelTimeline BeginTime="00:00:03.5"> <DoubleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Duration="00:00:01.5" To="500" /> <DoubleAnimation Storyboard.TargetName="circleButton2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Duration="00:00:00.5" To="0.0" /> </ParallelTimeline> </Storyboard> </Window.Resources> <Window.Triggers> <EventTrigger SourceName="goButton" RoutedEvent="Button.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource AccelerateStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource DecelerateStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource AccelerateDecelerateStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInBounceStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutBounceStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutBounceStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInElasticStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutElasticStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutElasticStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInExponentialStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutExponentialStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutExponentialStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInBackDirectionStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutBackDirectionStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutBackDirectionStoryboardKey}" /> <BeginStoryboard Storyboard="{StaticResource CircleStoryboardKey1 }" /> <BeginStoryboard Storyboard="{StaticResource CircleStoryboardKey2 }" /> </EventTrigger> <EventTrigger SourceName="linearButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="accelerateButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource AccelerateStoryboardKey }" /> </EventTrigger> <EventTrigger SourceName="decelerateButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource DecelerateStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="accelerateDecelerateButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource AccelerateDecelerateStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="easeInBounceButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInBounceStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="easeOutBounceButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }"/> <BeginStoryboard Storyboard="{StaticResource EaseOutBounceStoryboardKey }"/> </EventTrigger> <EventTrigger SourceName="easeInOutBounceButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutBounceStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="easeInElasticButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }"/> <BeginStoryboard Storyboard="{StaticResource EaseInElasticStoryboardKey }"/> </EventTrigger> <EventTrigger SourceName="easeOutElasticButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }"/> <BeginStoryboard Storyboard="{StaticResource EaseOutElasticStoryboardKey }"/> </EventTrigger> <EventTrigger SourceName="easeInOutElasticButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutElasticStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="easeInExponentialButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInExponentialStoryboardKey }" /> </EventTrigger> <EventTrigger SourceName="easeOutExponentialButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutExponentialStoryboardKey }" /> </EventTrigger> <EventTrigger SourceName="easeInOutExponentialButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInOutExponentialStoryboardKey }" /> </EventTrigger> <EventTrigger SourceName="easeInBackDirectionButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseInBackDirectionStoryboardKey }" /> </EventTrigger> <EventTrigger SourceName="easeOutBackDirectionButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource EaseOutBackDirectionStoryboardKey}" /> </EventTrigger> <EventTrigger SourceName="easeInOutBackDirectionButton" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }"/> <BeginStoryboard Storyboard="{StaticResource EaseInOutBackDirectionStoryboardKey }"/> </EventTrigger> <EventTrigger SourceName="circleButton1" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource CircleStoryboardKey1}" /> </EventTrigger> <EventTrigger SourceName="circleButton2" RoutedEvent="ButtonBase.Click"> <BeginStoryboard Storyboard="{StaticResource LinearStoryboardKey }" /> <BeginStoryboard Storyboard="{StaticResource CircleStoryboardKey2}" /> </EventTrigger> </Window.Triggers> <Grid ShowGridLines="False"> <Grid.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Canvas.Left" Value="10" /> <Setter Property="Background" Value="AliceBlue" /> </Style> </Grid.Resources> <Grid.RowDefinitions> <RowDefinition Height="45" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition Height="105" /> <RowDefinition/> </Grid.RowDefinitions> <Canvas Grid.Row="0"> <Button Name="linearButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Linear! </Button> </Canvas> <Canvas Grid.Row="1"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="64"> Accelerate / Decelerate </TextBlock> <Button Name="accelerateButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Accelerate! </Button> <Button Name="decelerateButton" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Decelerate! </Button> <Button Name="accelerateDecelerateButton" Canvas.Top="70"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Both! </Button> </Canvas> <Canvas Grid.Row="2"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="108"> Bounce! </TextBlock> <Button Name="easeInBounceButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Beginning! </Button> <Button Name="easeOutBounceButton" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> End! </Button> <Button Name="easeInOutBounceButton" Canvas.Top="70"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Both! </Button> </Canvas> <Canvas Grid.Row="3"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="108"> Elastic </TextBlock> <Button Name="easeInElasticButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Beginning! </Button> <Button Name="easeOutElasticButton" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> End! </Button> <Button Name="easeInOutElasticButton" Canvas.Top="70"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Both! </Button> </Canvas> <Canvas Grid.Row="4"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="108"> Exponential </TextBlock> <Button Name="easeInExponentialButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Beginning! </Button> <Button Name="easeOutExponentialButton" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> End! </Button> <Button Name="easeInOutExponentialButton" Canvas.Top="70"> <Button.RenderTransform> <TranslateTransform X="0" Y="0"/> </Button.RenderTransform> Both! </Button> </Canvas> <Canvas Grid.Row="5"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="80"> Circular Effects </TextBlock> <Button Name="circleButton1" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Circle 1! </Button> <Button Name="circleButton2" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0"/> </Button.RenderTransform> Circle 2! </Button> </Canvas> <Canvas Grid.Row="6"> <TextBlock Canvas.Left="85" Canvas.Top="-16" Foreground="LightGray" FontSize="108"> Back </TextBlock> <Button Name="easeInBackDirectionButton" Canvas.Top="10"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Beginning! </Button> <Button Name="easeOutBackDirectionButton" Canvas.Top="40"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> End! </Button> <Button Name="easeInOutBackDirectionButton" Canvas.Top="70"> <Button.RenderTransform> <TranslateTransform X="0" Y="0" /> </Button.RenderTransform> Both! </Button> </Canvas> <Canvas Grid.Row="7"> <Button Name="goButton" Canvas.Left="10" Canvas.Top="10" Background="LightGreen"> Go! </Button> </Canvas> </Grid> </Window> |