Page 1 of 1

Animating DependencyProperty

Posted: 11 Feb 2020, 23:02
by Feldruebe
Hello,

i am running into an error when i try to animate a dependency property.
I want to expose predefined render transforms to the user of the control through dependency properties.
The user can then define a storyboard to animate this properties.

In the code behind i have something like this:
public static readonly DependencyProperty ScaleXProperty = DependencyProperty.Register(
            "ScaleX", typeof(double), typeof(AnimatedTextBlock), new PropertyMetadata(1d));
            
 public double ScaleX
 {
            get { return (double)GetValue(ScaleXProperty); }
            set { SetValue(ScaleXProperty, value); }
 }            
 
The storyboard looks like this:
<Storyboard x:Key="Storyboard"> 
                <DoubleAnimation Storyboard.TargetProperty="(controls1:AnimatedTextBlock.ScaleX)"
                                                  From="2" To="1" Duration="0:0:0.5"/>
</Storyboard> 
In Unity i get the following errors:

[noesis] Can't animate 'Double' value with a DoubleAnimation
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:116)
Noesis.View:Noesis_View_Update(HandleRef, Double)
Noesis.View:Update(Double) (at Assets/NoesisGUI/Plugins/API/Core/View.cs:271)
NoesisView:LateUpdate() (at Assets/NoesisGUI/Plugins/NoesisView.cs:822)

[noesis] Can't animate property 'NoesisGui.Assets.Scripts.GuiUtility.Controls.AnimatedTextBlock.ScaleX' with a DoubleAnimation
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:116)
Noesis.View:Noesis_View_Update(HandleRef, Double)
Noesis.View:Update(Double) (at Assets/NoesisGUI/Plugins/API/Core/View.cs:271)
NoesisView:LateUpdate() (at Assets/NoesisGUI/Plugins/NoesisView.cs:822)

Am i doing something wrong or do i miss something?

Re: Animating DependencyProperty

Posted: 16 Feb 2020, 18:47
by sfernandez
That error is happening because in Noesis our API uses floats and to be compatible with WPF we made the DoubleAnimation/DoubleAnimationUsingKeyFrames to animate float values.

If you change your properties to be float the animation should work fine.
public static readonly DependencyProperty ScaleXProperty = DependencyProperty.Register(
  "ScaleX", typeof(float), typeof(AnimatedTextBlock), new PropertyMetadata(1.0f));
            
public float ScaleX
{
  get { return (float)GetValue(ScaleXProperty); }
  set { SetValue(ScaleXProperty, value); }
} 

Re: Animating DependencyProperty

Posted: 17 Feb 2020, 16:06
by Feldruebe
Thanks for the Answer. I will keep that in mind.

I worked around the problem by exposing the whole transforms (ScaleTransform, RotateTransform,...) as DependencyProperties.

Re: Animating DependencyProperty

Posted: 21 Feb 2020, 18:07
by jsantos
Thanks a lot for your feedback!