// Copyright (c) The Perspex Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System.Linq; namespace Perspex.Animation { /// /// Base class for control which can have property transitions. /// public class Animatable : PerspexObject { /// /// The property transitions for the control. /// private PropertyTransitions _propertyTransitions; /// /// Gets or sets the property transitions for the control. /// /// /// The property transitions for the control. /// public PropertyTransitions PropertyTransitions { get { if (_propertyTransitions == null) { _propertyTransitions = new PropertyTransitions(); } return _propertyTransitions; } set { _propertyTransitions = value; } } /// /// Reacts to a change in a value in order to animate the /// change if a is set for the property.. /// /// The event args. protected override void OnPropertyChanged(PerspexPropertyChangedEventArgs e) { if (e.Priority != BindingPriority.Animation && _propertyTransitions != null) { var match = _propertyTransitions.FirstOrDefault(x => x.Property == e.Property); if (match != null) { Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration); } } } } }