Browse Source

Use attached property

pull/6082/head
Wiesław Šoltés 5 years ago
parent
commit
84dd710fc1
  1. 4
      samples/RenderDemo/Pages/CustomAnimatorPage.xaml
  2. 18
      src/Avalonia.Animation/Animation.cs
  3. 1
      src/Avalonia.Animation/IAnimationSetter.cs
  4. 5
      src/Avalonia.Styling/Styling/Setter.cs

4
samples/RenderDemo/Pages/CustomAnimatorPage.xaml

@ -11,10 +11,10 @@
<Style.Animations>
<Animation Duration="0:0:1" IterationCount="Infinite">
<KeyFrame Cue="0%">
<Setter Property="Text" Value="" Animator="{x:Type pages:CustomStringAnimator}"/>
<Setter Property="Text" Value="" Animation.Animator="{x:Type pages:CustomStringAnimator}"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Text" Value="0123456789" Animator="{x:Type pages:CustomStringAnimator}"/>
<Setter Property="Text" Value="0123456789" Animation.Animator="{x:Type pages:CustomStringAnimator}"/>
</KeyFrame>
</Animation>
</Style.Animations>

18
src/Avalonia.Animation/Animation.cs

@ -194,6 +194,22 @@ namespace Avalonia.Animation
[Content]
public KeyFrames Children { get; } = new KeyFrames();
private static readonly Dictionary<object, Type> s_animators = new Dictionary<object, Type>();
public static Type GetAnimator(object obj)
{
if (s_animators.TryGetValue(obj, out var type))
{
return type;
}
return null;
}
public static void SetAnimator(object obj, Type value)
{
s_animators[obj] = value;
}
private readonly static List<(Func<AvaloniaProperty, bool> Condition, Type Animator)> Animators = new List<(Func<AvaloniaProperty, bool>, Type)>
{
( prop => typeof(bool).IsAssignableFrom(prop.PropertyType), typeof(BoolAnimator) ),
@ -248,7 +264,7 @@ namespace Avalonia.Animation
{
foreach (var setter in keyframe.Setters)
{
var handler = setter.Animator ?? GetAnimatorType(setter.Property);
var handler = Animation.GetAnimator(setter) ?? GetAnimatorType(setter.Property);
if (handler == null)
{

1
src/Avalonia.Animation/IAnimationSetter.cs

@ -6,6 +6,5 @@ namespace Avalonia.Animation
{
AvaloniaProperty Property { get; set; }
object Value { get; set; }
Type Animator { get; set; }
}
}

5
src/Avalonia.Styling/Styling/Setter.cs

@ -59,11 +59,6 @@ namespace Avalonia.Styling
}
}
/// <summary>
/// Gets or sets the property animator.
/// </summary>
public Type? Animator { get; set; }
public ISetterInstance Instance(IStyleable target)
{
target = target ?? throw new ArgumentNullException(nameof(target));

Loading…
Cancel
Save