// -----------------------------------------------------------------------
//
// Copyright 2014 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Animation
{
using System.Linq;
using System.Reactive.Linq;
///
/// 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 (this.propertyTransitions == null)
{
this.propertyTransitions = new PropertyTransitions();
}
return this.propertyTransitions;
}
set
{
this.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 && this.propertyTransitions != null)
{
var match = this.propertyTransitions.FirstOrDefault(x => x.Property == e.Property);
if (match != null)
{
Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
}
}
}
}
}