diff --git a/samples/RenderDemo/Pages/TransitionsPage.xaml b/samples/RenderDemo/Pages/TransitionsPage.xaml index f9f69fb341..ce5db380c0 100644 --- a/samples/RenderDemo/Pages/TransitionsPage.xaml +++ b/samples/RenderDemo/Pages/TransitionsPage.xaml @@ -141,6 +141,19 @@ + + + + @@ -166,6 +179,8 @@ + + diff --git a/src/Avalonia.Visuals/Animation/Transitions/BrushTransition.cs b/src/Avalonia.Visuals/Animation/Transitions/BrushTransition.cs new file mode 100644 index 0000000000..0f7501e279 --- /dev/null +++ b/src/Avalonia.Visuals/Animation/Transitions/BrushTransition.cs @@ -0,0 +1,29 @@ +using System; +using Avalonia.Animation.Animators; +using Avalonia.Media; + +namespace Avalonia.Animation +{ + /// + /// Transition class that handles with type. + /// Only values of will correctly transition. + /// + public class ISolidColorBrushTransition : Transition + { + private static readonly ISolidColorBrushAnimator s_animator = new ISolidColorBrushAnimator(); + + public override IObservable DoTransition(IObservable progress, IBrush oldValue, IBrush newValue) + { + var oldSolidBrush = AsImmutable(oldValue); + var newSolidBrush = AsImmutable(newValue); + + return new AnimatorTransitionObservable( + s_animator, progress, Easing, oldSolidBrush, newSolidBrush); + } + + private static ISolidColorBrush AsImmutable(IBrush brush) + { + return (ISolidColorBrush)(brush as ISolidColorBrush)?.ToImmutable(); + } + } +}